相关疑难解决方法(0)

ProcessStartInfo挂在"WaitForExit"上?为什么?

我有以下代码:

info = new System.Diagnostics.ProcessStartInfo("TheProgram.exe", String.Join(" ", args));
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
p.WaitForExit();
Console.WriteLine(p.StandardOutput.ReadToEnd()); //need the StandardOutput contents
Run Code Online (Sandbox Code Playgroud)

我知道我开始的进程的输出大约是7MB.在Windows控制台中运行它可以正常工作.不幸的是,这会在WaitForExit上无限期挂起.另请注意,对于较小的输出(例如3KB),此代码不会挂起.

ProcessStartInfo中的内部StandardOutput是否可能无法缓冲7MB?如果是这样,我该怎么做呢?如果没有,我做错了什么?

c# processstartinfo

179
推荐指数
8
解决办法
11万
查看次数

c#执行shell命令并获取结果

我正在执行命令提示符命令,如下所示:

string cmd = "/c dir" ; 
System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = cmd; 
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true; 
proc.Start();
Run Code Online (Sandbox Code Playgroud)

如何获取命令的输出?

c# shell command prompt output

15
推荐指数
1
解决办法
3万
查看次数

重定向进程输出C#

我想将Process的标准输出重定向到一个字符串,以便以后解析.我还希望在进程运行时看到屏幕上的输出,而不仅仅是当它完成运行时.

这甚至可能吗?

c# process output-redirect redirectstandardoutput

11
推荐指数
2
解决办法
2万
查看次数