3

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.

Community
  • 1
  • 1
0xBADF00D
  • 980
  • 1
  • 12
  • 25
  • 2
    If you already read the other thread, why didn't you read the [answer to your problem](http://stackoverflow.com/a/850856/880802), too? Hint: it's the first paragraph. And why `<` and `>` don't work is explained in the last one. – Nuffin Jan 23 '12 at 21:00
  • Everything after your `<` is no longer an argument to your application. Those are "switches" (so to speak) for the command line processor. – user7116 Jan 23 '12 at 21:17
  • possible duplicate of [Piping in a file on the command-line using System.Diagnostics.Process](http://stackoverflow.com/questions/850802/piping-in-a-file-on-the-command-line-using-system-diagnostics-process) – Cody Gray - on strike Jan 23 '12 at 22:51

1 Answers1

2

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

L.B
  • 114,136
  • 19
  • 178
  • 224
  • Ok I tried this, but now I got an onther error: Error: Input is not a standard raw PGM file. But everthing I do is process.StandardInput.Write(File.ReadAllBytes(sourceFile)) and Flush()+Close(). I does not change anything on the content on the file. – 0xBADF00D Jan 24 '12 at 09:44
  • If solved the problem with this [link](http://stackoverflow.com/questions/2956274/how-to-pass-filename-to-standardinput-process-in-c). The problem was solved by reading the file into a string, instead of a byte[]. Does anybody know why? Thanks to L.B. – 0xBADF00D Jan 24 '12 at 10:23