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位置在一起

  • 相关阅读:
    显示等待WebDriverWait+EC
    mac 上查看python3的各种安装路径
    layui弹窗全屏显示
    Mysql 一些细节方面解析(一)--MyISAM和InnoDB的主要区别和应用场景
    命令关闭tomcat
    xml 写sql语句文件头
    mysql update 修改多个字段and的语法问题
    zookeeper安装
    Java 基础--移位运算符
    SQL mybatis动态查询小结
  • 原文地址:https://www.cnblogs.com/gisoracle/p/14508184.html
Copyright © 2011-2022 走看看