简体   繁体   中英

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 . In C# however, I'm not sure how to pipe a devnull stream (Stream.Null?) into Process.StandardInput .

How can I skip an arbitrary number of "Press any key to continue..." prompts in a subprocess in C#?

With CliWrap , all the pipes are redirected to /dev/null by default (you can configure them).

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM