我想stdin从windows 中的外部进程向现有进程写入数据,并发现linux的类似问题:
如何将数据从Python中的不同本地/远程进程流式传输到程序的STDIN中?
https://serverfault.com/questions/443297/write-to-stdin-of-a-running-process-using-pipe
等等,但现在我想知道如何在Windows中这样做?
我尝试使用此代码,但我收到错误!
我也尝试运行程序并使用此鳕鱼发送标准输入但再次出错!
在CMD中:
type my_input_string | app.exe -start
my_input_string | app.exe -start
app.exe -start < pas.txt
Run Code Online (Sandbox Code Playgroud)
在python中:
p = subprocess.Popen('"C:\app.exe" -start', stdin=subprocess.PIPE, universal_newlines=True, shell=True)
grep_stdout = p.communicate(input='my_input_string')[0]
Run Code Online (Sandbox Code Playgroud)
错误是这样的:
ReadConsole()失败:句柄无效.
在C#中:
try
{
var startInfo = new ProcessStartInfo();
startInfo.RedirectStandardInput = true;
startInfo.FileName = textBox1.Text;
startInfo.Arguments = textBox2.Text;
startInfo.UseShellExecute = false;
var process = new Process();
process.StartInfo = startInfo;
process.Start();
Thread.Sleep(1000);
var streamWriter = process.StandardInput;
streamWriter.WriteLine("1");
}
catch (Exception ex)
{
textBox4.Text = ex.Message+"\r\n"+ex.Source; …Run Code Online (Sandbox Code Playgroud)