c# - The `Process` does not start with the special characters in the process argument -


i can run ffmpeg.exe -i test.flv -f flv - | ffplay -i - in cmd, can't run in c# codes when "|" in argument.

this code works :

  process process = new process();   process process .startinfo.filename = "ffmpeg.exe";   process process .startinfo.arguments =" -i test.flv "   process .start(); 

but code not working :

  process process = new process();   process process .startinfo.filename = "ffmpeg.exe";   process process .startinfo.arguments =" -i test.flv -f flv - | ffplay -i -"   process .start(); 

i tried codes did not effect:

   process process .startinfo.arguments =" -i test.flv -f flv - \| ffplay -i -"     process process .startinfo.arguments =" -i test.flv -f flv - \\| ffplay -i -"     process process .startinfo.arguments =@" -i test.flv -f flv - | ffplay -i -"     process process .startinfo.arguments ="\" -i test.flv -f flv - \| ffplay -i -\"" 

please tell me how can run ffmpeg.exe -i test.flv -f flv - | ffplay -i - in c# codes.

piping output 1 command feature of shell in execute commands. in .net, using process class need use shell (usually cmd.exe) achieve same effect.

// expands `c:\windows\system32\cmd.exe` process.startinfo.filename = environment.expandenvironmentvariables("%comspec%");  // build command line passed cmd.exe process.startinfo.arguments = "/c ffmpeg.exe -i test.flv -f flv - | ffplay -i -" 

additionally, depending on use case, want wait process finish:

process.waitforexit(); 

and possible evaluate exit code

if (process.exitcode != 0) // convention only! usually, exit of 0 means error. ymmv. 

finally, note pipelines, exit code returned here exit code of last command (in case ffplay).


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -