开发者

C# Process does not accept my parameters

I think the C# process class has a problem with accep开发者_如何转开发ting < or > characters when they are passed as paramaters.

When I call the following code, the executable returns me an error indicating that I passed more than one argument.

 proc = new Process();
 proc.StartInfo.FileName = this.spumux.SpumuxExe;
 proc.StartInfo.Arguments = "menu.xml < menu.mpg > newmenu.mpg";
 proc.StartInfo.UseShellExecute = false;
 proc.StartInfo.CreateNoWindow = true;
 proc.StartInfo.RedirectStandardOutput = true;
 proc.StartInfo.RedirectStandardError = true;
 proc.EnableRaisingEvents = true;
 proc.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
 proc.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
 proc.Exited += new EventHandler(ProcExited);
 proc.Start();
 proc.BeginOutputReadLine();
 proc.BeginErrorReadLine();

This code normally worked with every other executable I tried so far without any problems. So it's gotta do something with <, > characters

Any ideas?


The angle brackets in this case mean redirecting the input/output, which is done by cmd.exe, not by the started process.

You have two options:

  • call cmd.exe instead of your executable, and supply the executable as an argument (and the arguments for your exe as well)
  • redirect standard input/output yourself.


try "menu.xml \< menu.mpg \> newmenu.mpg". And you are adding 5 args. To make it one - do: "\"menu.xml \< menu.mpg \> newmenu.mpg\""


I'm not sure what your attempting to accomplish here. Are you trying to redirect IO with '<' and '>', or are you trying to pass these as arguments?

You can redirect IO by running CMD.exe with the /C option:

proc.StartInfo.FileName = @"C:\Windows\System32\Cmd.exe";
proc.StartInfo.Arguments = "/C \"" + this.spumux.SpumuxExe + " menu.xml < menu.mpg > newmenu.mpg\"";


I was only be able to solve this issue by creating a batch file, where I pass the arguments without "<", ">"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜