1
私はこの方法では、このコードを持っている:「StandardOutがリダイレクトされていないか、プロセスがまだ開始されていない」(Process.GetProcessById後)
int startApp()
{
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = "File.exe";
proc.Arguments = "someArguments";
proc.RedirectStandardInput = false;
proc.RedirectStandardOutput = true;
proc.UseShellExecute = false;
proc.CreateNoWindow = true;
Process p = Process.Start(proc);
Console.WriteLine(p.StandardOutput.ReadLine()); // Here it works!
return p.Id;
}
それから私は、Idがで返されるプロセスを使用してこのコードを実行します前の方法:
void readText(int processId)
{
Process p = Process.GetProcessById(processId);
Console.WriteLine(p.StandardOutput.ReadLine()); // Here does not work!
}
"StandardOut has not been redirected or the process hasn't started yet"
というのは失敗します。
なぜ私はProcess.StandardOutput
から読むことができないのですか?
'process'オブジェクト全体を' startApp'から返し、 'readText'でそれを使用して、プロセスIDで再取得しないようにしてください。 – vcsjones