如何捕获未发送到 stdout 的命令行文本?

发布于 2024-08-21 04:18:15 字数 304 浏览 16 评论 0原文

我在项目中使用 LAME 命令行 mp3 编码器。我希望能够看到某人正在使用什么版本。如果我只是执行没有参数的 LAME.exe,例如:

C:\LAME>LAME.exe
LAME 32-bits version 3.98.2 (http://www.mp3dev.org/)

usage: blah blah
blah blah

C:\LAME>

如果我尝试使用 > 将输出重定向到文本文件对于文本文件,文本文件为空。在 c# 中使用 System.Process 运行该文本时,可以从哪里访问该文本?

I am using the LAME command line mp3 encoder in a project. I want to be able to see what version someone is using. if I just execute LAME.exe with no paramaters i get, for example:

C:\LAME>LAME.exe
LAME 32-bits version 3.98.2 (http://www.mp3dev.org/)

usage: blah blah
blah blah

C:\LAME>

if i try redirecting the output to a text file using > to a text file the text file is empty. Where is this text accessable from when running it using System.Process in c#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

人│生佛魔见 2024-08-28 04:18:15

它可能会输出到 stderr 而不是 stdout。您可以通过执行以下操作重定向 stderr

LAME.exe 2> textfile.txt

如果这显示了您的信息,则 LAME 是输出到标准错误流。如果您用 C# 编写包装器,则可以重定向 标准错误 和来自 ProcessStartInfo

It may be output to stderr instead of stdout. You can redirect stderr by doing:

LAME.exe 2> textfile.txt

If this shows you information, then LAME is outputting to the standard error stream. If you write a wrapper in C#, you can redirect the standard error and output streams from ProcessStartInfo.

忆梦 2024-08-28 04:18:15
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = @"C:\LAME\LAME.exe";
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.UseShellExecute = false;

        proc.Start();
        string output = proc.StandardError.ReadToEnd();


        proc.WaitForExit();

        MessageBox.Show(output);

工作了。谢谢大家!

        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = @"C:\LAME\LAME.exe";
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.UseShellExecute = false;

        proc.Start();
        string output = proc.StandardError.ReadToEnd();


        proc.WaitForExit();

        MessageBox.Show(output);

worked. thanks all!

不…忘初心 2024-08-28 04:18:15

它可能正在使用 stderr。 cmd.exe 不允许您重定向 stderr,而我重定向它的唯一方法是使用 djgpp 工具。

It's probably using stderr. cmd.exe doesn't allow you to redirect stderr, and the only way I've ever redirected it is with a djgpp tool.

雄赳赳气昂昂 2024-08-28 04:18:15

它可能会被发送到 stderr,你尝试过吗?

查看 Process.StandardError< /a>.

尝试使用

C:\LAME>LAME.exe 2> test.txt

It might be sent to stderr, have you tried that?

Check out Process.StandardError.

Try it out using

C:\LAME>LAME.exe 2> test.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文