Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Diagnostics.Process pipe (vertical bar) not accepted as argument

I'm trying to execute this code using System.Diagnostics.Process. It works fine in command line. But in C# it's failing on the | character.

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

It gives the following error:

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

I've looked around on stackoverflow and found the following hint but it is also not working:

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

gives the following error:

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

like image 572
emp Avatar asked Apr 15 '14 19:04

emp


1 Answers

Thanks to Lee his comments, the problem has been resolved. Just invoke cmd.exe and pass it the full command:

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();
like image 146
emp Avatar answered Oct 23 '22 12:10

emp