[英]C# Process - Pipe devnull to input
In Python I can skip all "Press any key to continue..." prompts of a subprocess by specifying stdin=subprocess.DEVNULL
as an argument to subprocess.Popen
.在Python我可以跳过所有“按任意键继续......”通过指定子进程的提示
stdin=subprocess.DEVNULL
作为参数subprocess.Popen
。 In C# however, I'm not sure how to pipe a devnull stream (Stream.Null?) into Process.StandardInput
.但是,在 C# 中,我不确定如何将 devnull 流(Stream.Null?)通过管道传输到
Process.StandardInput
。
How can I skip an arbitrary number of "Press any key to continue..." prompts in a subprocess in C#?如何在 C# 的子进程中跳过任意数量的“按任意键继续...”提示?
With CliWrap , all the pipes are redirected to /dev/null
by default (you can configure them).使用CliWrap ,默认情况下所有管道都重定向到
/dev/null
(您可以配置它们)。
So you can do:所以你可以这样做:
await Cli.Wrap("child.exe").WithArguments("foo bar").ExecuteAsync();
If you want to pipe, you can use the pipe operator:如果要管道,可以使用管道运算符:
await using var input = File.Open("input.txt");
await using var output = File.Create("output.txt");
await using var error = File.Create("error.txt");
var cmd = input | Cli.Wrap("child.exe").WithArguments("foo bar") | (output, error);
await cmd.ExecuteAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.