相关疑难解决方法(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万
查看次数

使用.NET Process.Start运行时挂起进程 - 出了什么问题?

我在svn.exe周围写了一个快速而又脏的包装器来检索一些内容并用它做一些事情,但对于某些输入它偶尔会重复挂起并且无法完成.例如,一个调用是svn列表:

svn list "http://myserver:84/svn/Documents/Instruments/" --xml  --no-auth-cache --username myuser --password mypassword
Run Code Online (Sandbox Code Playgroud)

当我从命令shell执行此操作时,此命令行运行正常,但它在我的应用程序中挂起.运行它的我的c#代码是:

string cmd = "svn.exe";
string arguments = "list \"http://myserver:84/svn/Documents/Instruments/\" --xml  --no-auth-cache --username myuser --password mypassword";
int ms = 5000;
ProcessStartInfo psi = new ProcessStartInfo(cmd);
psi.Arguments = arguments;
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Normal;
psi.UseShellExecute = false;
Process proc = Process.Start(psi);
StreamReader output = new StreamReader(proc.StandardOutput.BaseStream, Encoding.UTF8);

proc.WaitForExit(ms);
if (proc.HasExited)
{
    return output.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)

这需要整整5000毫秒,永远不会完成.延长时间并没有帮助.在一个单独的命令提示符中,它立即运行,所以我很确定它与等待时间不足无关.但是,对于其他输入,这似乎工作正常.

我也尝试在这里运行一个单独的cmd.exe(其中exe是svn.exe,而args是原始的arg字符串),但仍然发生了挂起:

string cmd = "cmd";
string arguments = "/S /C \"" + exe + " …
Run Code Online (Sandbox Code Playgroud)

c# processstartinfo

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

标签 统计

c# ×2

processstartinfo ×2