从C#的进程中与python的input()进行交互

时间:2017-10-19 12:23:54

标签: c# python

这是我的 python脚本

print("hello world")
theInput = input(">\n")
print("eingegeben: " + theInput + "\n")

我想从C#中调用这个脚本并输入它。但只有“你好世界”被打印出来。

C#中的调用函数内容:

Process proc = new Process();
proc.StartInfo.FileName = "python.exe";
proc.StartInfo.Arguments = "I:\\testskript.py";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.StandardOutputEncoding = Encoding.UTF8;
proc.Start();

proc.StandardInput.WriteLine("asdf");

string content = "";
while (true)
{
    if (proc.StandardOutput.EndOfStream)
         break;         
    content +=proc.StandardOutput.ReadLine() + "<br />";
}

webBrowser1.DocumentText = content; // the output goes to a webBrowers on the GUI

proc.Close();

return;

0 个答案:

没有答案
相关问题