我一直在嘗試讀取解析形態分析的過程輸出。但我無法讀取pckimmo32.exe輸出。c#進程輸出不可讀pckimmo
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) –