请教一下关于process的问题

qq_32456381 2021-03-17 10:24:15
当我使用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;
}

错误图
...全文
125 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧