您的位置:首页 > 编程语言 > Python开发

C# 服务里面调用Python.exe 来执行python文件

2015-12-24 18:50 405 查看

问题描述:在WCF服务里面通过调用python.exe来执行py文件,像下面这样py文件路径+参数,用空格隔开。会出现调用结果为空的现象

System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(pyPath, filepath + Params);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
using (System.Diagnostics.Process process = System.Diagnostics.Process.Start(procStartInfo))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
return result;
}
}

设置pyton文件路径的可访问性(权限问题),右键——属性——安全——添加用户

在python里面引用arcpy。但在pyton64位exe可以,在python32位exe结果为空,用pythonshell去运行结果是对的。目前知道64位调用arcpy是ArcGISserver中的,32位是Destop中的。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: