可以说,我有一个.bat文件,其中文字样 回声HELLO 暂停通过Cmd.exe C#获取字符串
输出“HELLO”。 没有别的
如果我从C#开始进程,也许我想在进程中闲置,并把它输出到一个字符串的一切? 就像我扫描过程。
我得到的代码是这样做的,但是像0秒之后,当进程启动时,它需要输出什么,但只有第一个。 如果我有一个100行的bat文件,那么它只需要1个也许。
总而言之,一旦bat文件输出新的东西,我想在我的C#应用程序中得到它。
请帮
示例代码:
Directory.SetCurrentDirectory(@"C:\Users\WS\Desktop\Modded\");
Process p = new Process();
p.StartInfo.FileName = @"C:\Users\WS\Desktop\Modded\Launcher.bat";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
txtLog.Text =
p.StandardOutput.ReadToEnd();
p.Close();
~~ redpois0n
向我们显示您当前的代码。 (如何准备示例代码:http://tinyurl.com/so-hints) – Heinzi
Ill add now .... Directory.SetCurrentDirectory(@“C:\ Users \ WS \ Desktop \ Modded \”); 进程p = new Process(); p.StartInfo.FileName = @“C:\ Users \ WS \ Desktop \ Modded \ Launcher.bat”; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardOutput = true; p.Start(); txtLog.Text = p.StandardOutput.ReadToEnd(); p.Close(); – redpois0n
@ user841016:不要把它放在评论里,它隐藏在那里,不可读 - 放在*问题*中。 –