开发者

c# start process arguments pass in data

trying to pas开发者_开发问答s in data from a file as a cmd line argument in c# and running into issues

ProcessStartInfo startInfo1 = new ProcessStartInfo();
startInfo1.FileName = @"myexe.exe";
startInfo1.UseShellExecute = false;
startInfo1.RedirectStandardOutput = true;
startInfo1.WindowStyle = ProcessWindowStyle.Hidden;
startInfo1.WorkingDirectory = @"C:\myfolder\";
startInfo1.Arguments = "-cmd1 x -cmd2 y  < c:\\yesfile.txt";

the issue is with the < c:\yesfile.txt ...

when I debug and grab the .Arguments and execute from cmd line, works fine. running from code, i get

Invalid command line parameters: <

searching around, I cant find the way to do this (pass in data) from code. The exe I am calling doesn't take in the "y" as a cmd line arg so I have to pass it in from a file to run it automatically like this.

Update: how to get the std input and pass in a y (based on answer) - make sure you RedirectStandardInput = true; as well

       StreamWriter inputWriter = myProcess.StandardInput;
                    inputWriter.Write("y");
                    inputWriter.Flush();
                    inputWriter.Close();


That's because the redirections <, > etc. are handled by the shell and not by Windows - you can't use them from Process.Start.

You could instead seed your Process.StandardInput with a stream containing a 'y' and flag startInfo1.RedirectStandardInput = true;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜