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.

3
  • 2
    If you already read the other thread, why didn't you read the answer to your problem, too? Hint: it's the first paragraph. And why < and > don't work is explained in the last one. Commented Jan 23, 2012 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. Commented Jan 23, 2012 at 21:17
  • possible duplicate of Piping in a file on the command-line using System.Diagnostics.Process Commented Jan 23, 2012 at 22:51

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
If solved the problem with this link. The problem was solved by reading the file into a string, instead of a byte[]. Does anybody know why? Thanks to L.B.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.