簡體   English   中英

啟動python時C#進程WaitForExit掛起

[英]C# Process WaitForExit hangs when starting python

我使用Process類啟動Python,如下所示(在線程中):

ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "python.exe";
info.Arguments = "test.py";
Process p = new Process();
p.StartInfo = info;
p.RedirectStandardOutput = true;
p.RedirectStandardError = true;
...
p.Start();
p.WaitForExit();

當Python以錯誤結尾(Python進程不再顯示在Windows任務管理器中)時,WaitForExit仍然掛起。 但是,如果我改用IronPython ,它可以正常工作。 誰能告訴我為什么?

解決。 重定向和ErrorDataReceived / OutputDataReceived事件實現導致此問題,請改用Redirects和StreamReader。

嘗試將python.exe更改為pythonw.exe

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM