471,071 Members | 4,765 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Capture Batch file return Value

Hi guy's

I have a batch file which return's me the string output

I success to execute the batch file from C#.Net, but unable to capture return value, I need that return string to be use in rest of my application

System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.EnableRaisingEvents = false;

proc.StartInfo.FileName = "S:\\Sadad_Link\\CMD\\Getuuid.bat";


This is how i execute the batch file, but for capturing return value i check all the properies for "proc" with no reasult

I will really appreciate, if somebody helps me out

Thank's in advance


Apr 21 '08 #1
1 2013
If your batch script only prints the string you are interested you can read the stdout that generate its execution...

Expand|Select|Wrap|Line Numbers
  1. using (StreamReader sr = proc.StandardOutput)
  2. {
  3.      myString = sr.ReadToEnd();
  4. }
You can also use piping inside your batch script to store the string in a text file and then read it from you code.

Expand|Select|Wrap|Line Numbers
  1. task1
  2. task2
  3. ...
  4. getMyString > myString.txt
  5. ...
Hope this help.
Apr 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by David Every | last post: by
1 post views Thread by code_wrong | last post: by
1 post views Thread by Kannan.V [MCSD.net] | last post: by
2 posts views Thread by Stephen | last post: by
reply views Thread by j101 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.