ArcGIS Pro运行Python脚本
// TODO: fix the path to test1.py so that it points to the proper file location 关注微信公众号:gisoracle
var pathProExe = System.IO.Path.GetDirectoryName((new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath); if (pathProExe == null) return; pathProExe = Uri.UnescapeDataString(pathProExe); pathProExe = System.IO.Path.Combine(pathProExe, @"Python\envs\arcgispro-py3"); System.Diagnostics.Debug.WriteLine(pathProExe); var pathPython = System.IO.Path.GetDirectoryName((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath); if (pathPython == null) return; pathPython = Uri.UnescapeDataString(pathPython); System.Diagnostics.Debug.WriteLine(pathPython); var myCommand = string.Format(@"/c """"{0}"" ""{1}""""", System.IO.Path.Combine(pathProExe, "python.exe"), System.IO.Path.Combine(pathPython, "test1.py")); System.Diagnostics.Debug.WriteLine(myCommand); var procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", myCommand); procStartInfo.RedirectStandardOutput = true; procStartInfo.RedirectStandardError = true; procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo = procStartInfo; proc.Start(); string result = proc.StandardOutput.ReadToEnd(); string error = proc.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(error)) result += string.Format("{0} Error: {1}", result, error); System.Windows.MessageBox.Show(result);
python文件位置和程序exe位置在一起