通过命令行参数从C#到一个外部的exe [英] Passing Command-line arguments from C# to a external exe

查看:132
本文介绍了通过命令行参数从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.pbm
  • write to StandardInput of your process
  • read from StandardOutput of your process
  • write to result.pbm

< A HREF =http://technet.microsoft.com/en-us/library/bb490982.aspx相对=nofollow>使用命令重定向操作符

这篇关于通过命令行参数从C#到一个外部的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆