C# 进程 - 管道 devnull 到输入

C# Process - Pipe devnull to input

在 Python 中,我可以通过将 stdin=subprocess.DEVNULL 指定为 subprocess.Popen 的参数来跳过子进程的所有 "Press any key to continue..." 提示。然而,在 C# 中,我不确定如何将 devnull 流(Stream.Null?)通过管道传输到 Process.StandardInput.

如何在 C# 的子进程中跳过任意数量的 "Press any key to continue..." 提示?

使用CliWrap,默认情况下所有管道都重定向到/dev/null(您可以配置它们)。

所以你可以这样做:

await Cli.Wrap("child.exe").WithArguments("foo bar").ExecuteAsync();

如果要管道化,可以使用管道运算符:

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