C# 服務裏面調用Python.exe 來執行python文件

問題描述:在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中的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章