4

I am looking for a c# example project of a WinForms app which redirects the output from a batch file running in background to any kind of WinForms control.

Any suggestions?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
koleto
  • 95
  • 1
  • 3

2 Answers2

6

I don't know if you're going to find a direct example, but it's not overly difficult. I don't have time to write all the code for you, but I can give you the code from MSDN:

Process myProcess = new Process();

ProcessStartInfo myProcessStartInfo = 
    new ProcessStartInfo("C:\\MyBatchFile.bat" );
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;

myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();

StreamReader myStreamReader = myProcess.StandardOutput;

// Read the standard output of the spawned process.
string myString = myStreamReader.ReadToEnd();

myProcess.Close();

// Now you have the output of the batch file in myString
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
1

See this answer here.

It will show you how to redirect the output to an event. You can then take the output and put it into your win control.

Community
  • 1
  • 1
David Basarab
  • 72,212
  • 42
  • 129
  • 156