C#中通过Process运行Python脚本
来源:互联网 发布:如何自学sql 编辑:程序博客网 时间:2024/05/19 19:59
<pre name="code" class="csharp">
<pre name="code" class="csharp"><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="csharp">public void set_Python_Argv() { IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pLayer; IDataLayer dl = (IDataLayer)m_pLayer; IWorkspaceName ws = ((IDatasetName)(dl.DataSourceName)).WorkspaceName; string path = ws.PathName; //设置脚本参数 string sArguments = @"shape_analyze.py";<span style="white-space:pre"></span>//这里是python的文件名字 string file_name = m_pLayer.Name;<span style="white-space:pre"></span>//要被传入的文件名,不含后缀 RunPythonScript(sArguments, path, file_name); } public static void RunPythonScript(string sArgName, string ws_name, string file_name) {//调用脚本 string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + sArgName;// 获得python文件的绝对路径 string sArguments = path; if (ws_name.Length > 0 || file_name.Length > 0) { sArguments =sArguments + " " + ws_name + " " + file_name;//传递参数 } //设置进程并运行 Process p = new Process(); p.StartInfo.FileName = "F:\\ArcGIS10.2\\python.exe"; p.StartInfo.Arguments = sArguments; p.Start(); p.WaitForExit(); }
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">以上代码是C#+Arc Engine项目的一部分,传入一个.shp(图层文件)到shape_analyze.py,以命令行参数的形式传递</span>
ws_name = str(sys.argv[1])<span style="white-space:pre"></span>//接受参数file_name = str(sys.argv[2])fc = ws_name + "\\" + file_name + ".shp"//组合出完整的文件名
0 0
- C#中通过Process运行Python脚本
- c#中运行sql脚本
- ubuntu中运行python脚本
- ubuntu中运行python脚本
- C#中 以管理员权限运行脚本
- C#中让WebBrowser运行Javascript脚本
- 怎样通过C#运行一个.sql的脚本文件?
- python 中运行linux shell脚本
- Xcode 4 中如何运行 Python 脚本?
- 在notepad++中直接运行python脚本
- 在CMD命令行中运行python脚本
- Python脚本在cmd中运行步骤
- 【转】C#中调用python脚本
- 通过场景运行脚本向数据库中插入数据失败
- Python:定时运行脚本
- Python 定时运行脚本
- 如何运行Python脚本
- Python批量运行脚本
- leetcode之Binary Tree Paths
- linux:vim NERDTree 安装和使用
- spring 拦截器
- Android框架 - Volley
- 使用 .NET 平台,如何玩转 Universal Windows 应用?
- C#中通过Process运行Python脚本
- JavaScript document.all 用法(oninput、onpropertychange事件的使用)
- genymotion模拟器结合Android studio使用
- 【Tomcat】配置https及访问http自动跳转至https
- 数据结构和算法经典100题-第28题
- 矩阵连乘 DP
- 如何得到iPhone手机的UUID
- sql 不等于 字符串要加单引号
- 使用ftp