本文介绍了通过命令行参数从C#到一个外部的exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我也有类似的问题,因为已经解决了的此处。但我想不通,这个问题是怎么解决的。我有一个程序,得到的放慢参数定义输入和输出文件。运行此从赞扬行,一切工作正常:I have a similar problem as already solved here. But I can not figure out, how the problem got solved. I have a program that get paramter the define a input and output file. Running this from Commend line, all works fine:D:\Tools\siftDemoV4>siftWin32.exe -display < D:\tmp\SrcPgm\image000.pbm > result.pbm 但通过的System.Diagnostics.Process运行,无法正常工作。我得到的错误无效的命令行参数:<并在此之后出现System.InvalidOperationException。 But running via System.Diagnostics.Process, does not work. I get the error "Invalid command line argument: <" and after this a System.InvalidOperationException occurs. var process = new Process(){ StartInfo = { Arguments = string.Format(@"-display < {0} > {1}", configuration.Source, configuration.Destination), FileName = configuration.PathToExternalSift, RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, ErrorDialog = false, }};process.EnableRaisingEvents = true;process.Exited += OnProcessExited;process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);process.ErrorDataReceived += new DataReceivedEventHandler(process_ErrorDataReceived);process.Start();process.BeginOutputReadLine();process.BeginErrorReadLine(); 我已经尝试过写process.StandardInput我打电话的Process.Start()之后,但使用时,调试器,外部程序是一段已经完成(HasExited == true)而I already tried to write to process.StandardInput after I called process.Start(), but when using the debugger, the external program was sometime already finished (HasExited==true).任何人都可以解释我是如何可以通过这个特殊的< >参数给PROGRAMM?Can anybody explain how I can pass this special "<" ">" parameters to the programm?最好的问候! 顺便说一句,我检查了路径多的时候,他们是正确的。By the way, I checked the path multiple time, they are correct.推荐答案您唯一需要的参数是 -display 其他人则没有参数的程序,应该由您使用 RedirectStandardInput 和 RedirectStandardOutput The only parameter you need is -display Others are not parameters to the program and should be handled by you by using RedirectStandardInput and RedirectStandardOutput例如: 读取文件 D:\tmp\SrcPgm\image000.pbm 写 StandardInput 流程 从 StandardOutput 的过程中阅读 写 result.pbm read the file D:\tmp\SrcPgm\image000.pbmwrite to StandardInput of your processread from StandardOutput of your processwrite to result.pbm 使用命令重定向操作符 这篇关于通过命令行参数从C#到一个外部的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 17:43