Print execution of batch file line-by-line?

B

brianbasquille

Hello all,

Hope you can help me with this little conundrum!

I'm running a batch file and want to print the execution of it
line-by-line.

Best reference i could find was:
http://www.developerfusion.co.uk/show/4662/
- it's in VB but pretty much identical to the C#. But this only prints
the output of the batch file at the end.

Tried to manipulate it to work with mine to print line by line but it
either says the process has finished or it simply fails.

// start code
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="temp.bat";
proc.StartInfo.RedirectStandardOutput=true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();

while(proc.Responding)
MessageBox.Show(proc.StandardOutput.ReadLine());

File.Delete("temp.bat");
// end code

Tried putting the WaitForExit() command after the while block which
didn't work either.

Any suggestions or pointers on how to get this working?

Thanks in advance,

Brian
 
C

Charles Calvert

Hope you can help me with this little conundrum!

I'm running a batch file and want to print the execution of it
line-by-line.

I've only done this sort of thing under Win32, not .NET, (and it's
been a long time) but it should be possible to do using the raw Win32
API if nothing else.

You need to attach a named pipe to the STDOUT of the console window
that the process uses. Here's an article that might be useful. It
shows how to do it in MFC, but it's easy enough to translate to Win32:
<http://www.codeguru.com/cpp/w-d/console/redirection/article.php/c3955/>.

Here's an MSDN article:
<http://msdn.microsoft.com/library/d..._process_with_redirected_input_and_output.asp>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top