开发者

Looking for example of C# WinForms app showing output from a batch file

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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜