當我使用process呼叫python.exe執行python腳本時,如果python腳本中print包含了中文,使用StandardOutput讀取回傳值時會報錯
代碼如下:path是腳本地址
public string test(string path)
{
string a = "";
try
{
Process p = new Process();
p.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + "/Python27/ArcGIS10.6/python.exe";
string sArguments = path; //python file
sArguments += " valid_q"; // the arguments required by the python file
p.StartInfo.Arguments = sArguments;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
a =p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
catch (Exception e) { return e.ToString(); }
return a;
}
錯誤圖
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/268699.html
標籤:ASP.NET
上一篇:共享檔案夾有時候寫入檔案非常慢
