我想重定向Process在richTextBox中的标准输出。这是我的流程配置,
string command = "/K perl C:\\Server.pl ";
ProcessStartInfo startInfo = new ProcessStartInfo();
Process proc = new Process();
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = command;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
proc.StartInfo = startInfo;
proc.OutputDataReceived += (s, ea) => this.richTextBox1.AppendText(ea.Data);
proc.Start();
proc.BeginOutputReadLine();这是我的Server.pl文件
print "Server1 \n";
while(1)
{
print "Server \n";
sleep 1;
}但是当我运行这个程序时,cmd.exe只是黑色的,没有在richTextBox中打印。但是当我改变
startInfo.RedirectStandardOutput = false;我把这个放进了我的cmd.exe:
Server1
Server
Server
Server
...我怎么才能解决这个问题?
发布于 2014-10-29 14:32:58
可能就像禁用perl脚本中的输出缓冲区一样简单。这是使用$|特殊变量完成的(参见珀尔瓦)。
$| = 1;
print "Server1 \n";
...https://stackoverflow.com/questions/26632065
复制相似问题