forked from zLulus/NotePractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (35 loc) · 1.16 KB
/
Program.cs
File metadata and controls
43 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpUsingPythonDemo
{
class Program
{
static void Main(string[] args)
{
string progToRun = "test.py";
char[] spliter = { '\r' };
Process proc = new Process();
proc.StartInfo.FileName = "python.exe";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
string psw = "123456";
string parameters2 = "haha";
//文件路径+参数集合
proc.StartInfo.Arguments = string.Concat(progToRun, " ", psw.ToString()," ", parameters2.ToString());
proc.Start();
StreamReader sReader = proc.StandardOutput;
string[] output = sReader.ReadToEnd().Split(spliter);
foreach (string s in output)
Console.WriteLine(s);
proc.WaitForExit();
//取出计算结果
Console.WriteLine(output[0]);
Console.Read();
}
}
}