I'm working on a SW that parses file with commands and it needs to execute all the commands . Looking thourgh StackOverFlow i found the following snippet:
String command = @".\wrap.exe sys";
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.FileName = "CMD.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.Arguments = command;
myProcess.Start();
string output = myProcess.StandardOutput.ReadToEnd();
myProcess.WaitForExit();
}
For some reason the command myProcess.StandardOutput.ReadToEnd()
hangs if i run it(Even if i change the order of this command and this command myProcess.WaitForExit()
and the standard Error output command also hangs(any ideas why this commands hangs?).
If i change FileName = "CMD.exe"
to FileName = "wrap.exe"
and Arguments ="sys"
it will work.
The problem is that i don't want to split it to arguments and fileName. Is there a way to do so(e.g. in Python using subprocess) ?