C# WPF で記述された GUI コントローラーがあり、引数を使用して Python スクリプトを実行します。この python スクリプトには、ファイルへの出力と書き込みがいくつかあります。stdout と stderr の出力を TextBlock にリダイレクトします。しかし、この出力のどれも機能しません。何か案は?
C# ランナー:
...
pr.StartInfo.FileName = pythonPath;
pr.StartInfo.Arguments = scriptPath + " " + args;
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.RedirectStandardOutput = true;
pr.StartInfo.RedirectStandardError = true;
pr.StartInfo.CreateNoWindow = true;
pr.ErrorDataReceived += new DataReceivedEventHandler(sortErrorHandler);
pr.OutputDataReceived += new DataReceivedEventHandler(sortOutputHandler);
pr.EnableRaisingEvents = true;
//pr.Exited += new EventHandler(whenExitProcess);
TB.Text = "";
pr.Start();
pr.BeginOutputReadLine();
pr.BeginErrorReadLine();
}
e.Handled = true;
}
private void sortErrorHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
Dispatcher.BeginInvoke(new MethodInvoker(delegate
{
if (!String.IsNullOrEmpty(outLine.Data))
{
TB.Text += outLine.Data + Environment.NewLine;
}
}));
}
private void sortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
Dispatcher.BeginInvoke(new MethodInvoker(delegate
{
if (!String.IsNullOrEmpty(outLine.Data))
{
TB.Text += outLine.Data + Environment.NewLine;
}
}));
}
パイソン:
print "Hello"
file.open("test", "a")
file.write("Hello again")
file.close()
... remaining code
さて、sys.stderr.write("test") は動作していますが、stdout と stderr の違いは何でしょうか?