Passing Command-line arguments from C# to a extern

2019-02-26 05:37发布

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

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();

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).

Can anybody explain how I can pass this special "<" ">" parameters to the programm?

Best Greetings!

By the way, I checked the path multiple time, they are correct.

1条回答
The star\"
2楼-- · 2019-02-26 06:18

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

E.g

  • read the file D:\tmp\SrcPgm\image000.pbm
  • write to StandardInput of your process
  • read from StandardOutput of your process
  • write to result.pbm

Using command redirection operators

查看更多
登录 后发表回答