C# 进程不接受我的参数
我认为 C# 进程类在接受 <
或 >
字符作为参数传递时存在问题。
当我调用以下代码时,可执行文件返回一个错误,表明我传递了多个参数。
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();
该代码通常可以与我迄今为止尝试过的所有其他可执行文件一起使用,没有任何问题。所以它必须用 <
、>
字符做一些事情
有什么想法吗?
I think the C# process class has a problem with accepting <
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试
“menu.xml \newmenu.mpg”
。并且您要添加 5 个参数。要使其成为一个 - 执行:"\"menu.xml \<菜单.mpg \>新菜单.mpg\""
try
"menu.xml \< menu.mpg \> newmenu.mpg"
. And you are adding 5 args. To make it one - do:"\"menu.xml \< menu.mpg \> newmenu.mpg\""
我不确定你想在这里完成什么。您是否尝试使用“<”重定向 IO和“>”,或者您是否试图将它们作为参数传递?
您可以通过使用 /C 选项运行 CMD.exe 来重定向 IO:
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:
我只能通过创建一个批处理文件来解决这个问题,在该文件中我传递的参数不带“<”、“>”
I was only be able to solve this issue by creating a batch file, where I pass the arguments without "<", ">"
在这种情况下,尖括号意味着重定向输入/输出,这是由 cmd.exe 完成的,而不是由启动的进程完成的。
您有两个选择:
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: