苏小测

导航

 

https://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//000100000m0s000000

C# 调用 python脚本

 1 // Executes a shell command synchronously.
 2 // Example of command parameter value is
 3 // "python " + @"C:\scripts\geom_input.py".
 4 //
 5 public static void ExecuteCommand(object command)
 6 {
 7     try
 8     {
 9         // Create the ProcessStartInfo using "cmd" as the program to be run,
10         // and "/c " as the parameters.
11         // "/c" tells cmd that you want it to execute the command that follows,
12         // then exit.
13         System.Diagnostics.ProcessStartInfo procStartInfo = new
14             System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
15 
16         // The following commands are needed to redirect the standard output.
17         // This means that it will be redirected to the Process.StandardOutput StreamReader.
18         procStartInfo.RedirectStandardOutput = true;
19         procStartInfo.UseShellExecute = false;
20 
21         // Do not create the black window.
22         procStartInfo.CreateNoWindow = true;
23 
24         // Now you create a process, assign its ProcessStartInfo, and start it.
25         System.Diagnostics.Process proc = new System.Diagnostics.Process();
26         proc.StartInfo = procStartInfo;
27         proc.Start();
28 
29         // Get the output into a string.
30         string result = proc.StandardOutput.ReadToEnd();
31 
32         // Display the command output.
33         Console.WriteLine(result);
34     }
35     catch (Exception objException)
36     {
37         Console.WriteLine(objException.Message);
38         // Log the exception and errors.
39     }
40 }
posted on 2021-01-26 14:53  苏小测  阅读(172)  评论(0编辑  收藏  举报