zoukankan      html  css  js  c++  java
  • 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, @"Pythonenvsarcgispro-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位置在一起

  • 相关阅读:
    vijos 1426
    2455 繁忙的都市
    2104 删除物品
    3235 战争
    BZOJ 2962
    COGS 265 线段覆盖
    P2184 贪婪大陆
    0729模拟赛解题报告
    BZOJ 1012
    BZOJ 2763
  • 原文地址:https://www.cnblogs.com/gisoracle/p/14508184.html
Copyright © 2011-2022 走看看