使用 Shell 执行重定向标准输出

Redirect Standard Output with Shell Execute

我了解如何从 C# 中的 Process 个对象重定向 StandardIO 流。但是,我必须使用 ShellExecute 才能使特定命令起作用。

因此,我无法重定向我需要用于记录目的的这些流。

我试过这样重定向它:

procStart.FileName = m1g;
procStart.Arguments = ">> output.txt";

此时我打算只读回文本文件,但这似乎行不通。

是否可以这样做?

管道命令由cmd.exe实现。所以你需要 运行 cmd /c 并添加你的可执行路径作为参数

Process.Start("cmd.exe", "/c " + yourexecutablecommandline + " >> output.txt" );