Is there a way to have a batch file run within a windows form application in C#?
So anyways, I'开发者_高级运维ve been working on a batch IDE, and I was wondering if there was a good way to effectively embed the file into the form.
It would function sort of like a debug mode, where at any time, the user can click a button, and the batch file would load into the actual form.
Like the black cmd window would be embedded into the form... Is there any way to do that?
ProcessStartInfo psi = new ProcessStartInfo();
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.FileName = "C:\\echo.cmd";
var p = Process.Start(psi);
Console.WriteLine(p.StandardOutput.ReadToEnd());
And in C:\echo.cmd
I have just basic echo hello!
. When this code is executed - you'll see hello!
received from batch's output stream.
Note that if executed command will wait for some input - ReadToEnd()
can't return. In this case you should use Process.OutputDataReceived
event.
Look at the process object and the StandardInput, StandardOutput and StandardError streams. That is essentially all the command window is showing with some special handling of control characters.
精彩评论