0
我想在richTextBox
中重定向Process
的標準輸出。這裏是我的工藝配置,C#進程RedirectStandardOutput不重定向
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
...
我如何解決這個問題?
我知道這是可能的運行'perl.exe',而不是'cmd.exe',但基於某些原因,我需要讓這個解決方案工作,CMD.EXE – 2014-10-29 14:23:15