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

  • 相关阅读:
    Class文件和JVM的恩怨情仇
    详解及对比创建线程的三种方式
    浅析Java中线程组(ThreadGroup类)
    简单定义多线程!
    五分钟看懂UML类图与类的关系详解
    LeetCode刷题--14.最长公共前缀(简单)
    LeetCode刷题--13.罗马数字转整数(简答)
    动态规划算法详解及经典例题
    LeetCode--9.回文数(简单)
    LeetCode刷题--7.整数反转(简单)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/14508184.html
Copyright © 2011-2022 走看看