【发布时间】:2016-12-07 07:38:58
【问题描述】:
我一直在尝试读取进程输出以进行形态分析。但我无法读取 pckimmo32.exe 输出。
public static string Problem1()
{
ProcessStartInfo _startInfo = new ProcessStartInfo();
Process p = new Process();
StringBuilder outputStringBuilder = new StringBuilder();
string filePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\PC-KIMMO\pckimmo32.exe";
var file = new FileInfo(filePath);
p.StartInfo = _startInfo;
_startInfo.UseShellExecute = false;
_startInfo.RedirectStandardOutput = true;
_startInfo.RedirectStandardInput = true;
_startInfo.WorkingDirectory = file.Directory.FullName;
_startInfo.FileName = file.FullName;
p.OutputDataReceived += (sender, eventArgs) => outputStringBuilder.AppendLine(eventArgs.Data);
p.Start();
p.BeginOutputReadLine();
var myWriter = p.StandardInput;
myWriter.AutoFlush = true;
myWriter.WriteLine("synthesize kitap +Noun +A3sg +P2sg +Loc");
myWriter.Close();
p.WaitForExit();
var output = outputStringBuilder.ToString();
return output;
}
public static void Display(DataReceivedEventArgs nes)
{
Console.WriteLine(nes.Data);
}
我可以读取另一个文本 exe 文件输出。
public static string Problem2()
{
ProcessStartInfo _startInfo = new ProcessStartInfo();
Process p = new Process();
StringBuilder outputStringBuilder = new StringBuilder();
string filePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\RTest\bin\debug\RTest.exe";
var file = new FileInfo(filePath);
p.StartInfo = _startInfo;
_startInfo.UseShellExecute = false;
_startInfo.RedirectStandardOutput = true;
_startInfo.RedirectStandardInput = true;
_startInfo.WorkingDirectory = file.Directory.FullName;
_startInfo.FileName = file.FullName;
p.OutputDataReceived += (sender, eventArgs) => outputStringBuilder.AppendLine(eventArgs.Data);
p.Start();
p.BeginOutputReadLine();
var myWriter = p.StandardInput;
myWriter.AutoFlush = true;
myWriter.Close();
p.WaitForExit();
var output = outputStringBuilder.ToString();
return output;
}
Problem2方法是成功读输出,我要读输出Problem1方法。
我相信我在正确的轨道上,但只需要几个指针。
【问题讨论】:
-
pckimmo.exe 已使用错误输出进行输出。我可以用 errorinput 读取输出。 (RedirectStandardError , ErrorDataReceived, BeginErrorReadLine)