gpt4 book ai didi

c# - System.Diagnostics.Process 管道(竖线)不被接受为参数

转载 作者:太空狗 更新时间:2023-10-29 23:07:34 28 4
gpt4 key购买 nike

我正在尝试执行 this code使用 System.Diagnostics.Process。它在命令行中工作正常。但在 C# 中,它在 | 字符上失败。

var myProcess = new Process();
var p = new ProcessStartInfo();

var sArgs = " -i emp.mp3 -f wav - | neroAacEnc -ignorelength -q 0.5 -if - -of emp.mp4";
p.FileName = "ffmpeg.exe";
p.CreateNoWindow = false;
p.RedirectStandardOutput = false;
p.UseShellExecute = false;
p.Arguments = sArgs;

myProcess.StartInfo = p;

myProcess.Start();
myProcess.WaitForExit();

它给出了以下错误:

Unable to find a suitable output format for '|': Invalid argument

我查看了 stackoverflow 并发现了以下提示,但它也不起作用:

var psi = new ProcessStartInfo("ffmpeg.exe");
psi.Arguments =
"\"-i emp.mp3 -f wav -\" | \"neroAacEnc -ignorelength -q 0.5 -if - -of emp.mp4\"";
psi.CreateNoWindow = false;
psi.UseShellExecute = false;

var process = new Process { StartInfo = psi };

process.Start();
process.WaitForExit();

出现以下错误:

Unrecognized option 'i emp.mp3 -f wav -'
Failed to set value '|' for option 'i emp.mp3 -f wav -'

最佳答案

感谢Lee他的意见,问题已经解决了。只需调用 cmd.exe 并将完整命令传递给它:

var myProcess = new Process();
var p = new ProcessStartInfo("cmd.exe");
var sArgs = "/C ffmpeg.exe -i emp.mp3 -f wav - | neroAacEnc -ignorelength -q 0.5 -if - -of emp.mp4";
p.CreateNoWindow = false;
p.RedirectStandardOutput = false;
p.UseShellExecute = false;
p.Arguments = sArgs;
myProcess.StartInfo = p;
myProcess.Start();
myProcess.WaitForExit();

关于c# - System.Diagnostics.Process 管道(竖线)不被接受为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23092519/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com