I know there are several post about passing arguments to a program but I haven't been able to solve my problem.
I am trying to pass some arguments to a program from my c# code.
When adding the arguments /c < input.txt | program2 > output.txt
I get an System.InvalidOperationException
.
With no arguments passed, the code works fine and program1
starts.
I have not been able to figure out how to explain my arguments correct.
Possibly the use of <
, >
, |
and the fact that there is a second program among the arguments gets me into trouble?
This works fine in cmd
.
My code:
var myProcess = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "program1",
Arguments = "/c < input.txt | program2 > output.txt",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = false
}
};
myProcess.Start();
while (!myProcess.StandardOutput.EndOfStream)
{
string line = myProcess.StandardOutput.ReadLine();
}
myProcess.WaitForExit();