私はいくつかの引数をつけてPythonスクリプトを実行するC#プログラムを作成しています。エラーがなくProcess ExitCodeが0(デバッガを介してチェック)であっても、プログラムは実行されません(メッセージを出力するだけでなく、ファイルに書き込むことも想定されています)。どこが間違っていますか?C#からpythonスクリプトを呼び出すとエラーがスローされずに呼び出されない
static private string ExecutePython(string sentence) {
// full path of python interpreter
string python = @"C:\Python27\python.exe";
// python app to call
string myPythonApp = @"C:\Users\user_name\Documents\pos_edit.py";
// Create new process start info
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
// make sure we can read the output from stdout
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.Arguments = string.Format("{0} {1}", myPythonApp, sentence);
Process myProcess = new Process();
// assign start information to the process
myProcess.StartInfo = myProcessStartInfo;
// start process
myProcess.Start();
// Read the standard output of the app we called.
StreamReader myStreamReader = myProcess.StandardOutput;
string myString = myStreamReader.ReadToEnd();
// wait exit signal from the app we called
myProcess.WaitForExit();
// close the process
myProcess.Close();
return myString;
}
"user_name"にスペースが含まれていませんか? – Aya
[c#のpythonスクリプトを実行する]の可能な複製(http://stackoverflow.com/questions/11779143/run-a-python-script-from-c-sharp) – Mate
@Aya no。しかし、私はstdoutを取ることなく仕事をする選択肢を得ました。 – goluhaque