ProcessStartInfo startInfo = new ProcessStartInfo();
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "tsvc -a -st rifs -h "+textBox1+" -sn "+textBox2+" -status";
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
richTextBox1.Text = process.StandardOutput.ReadToEnd();
I need to run a command in
cmd
that will take 2 parameters that will be inserted to textBox1 and textBox2 and then sending the output to the richTextBox1.When running it this way I get :
first chance exception of type 'System.InvalidOperationException' occurred in System.dll
Additional information: StandardOut has not been redirected or the process hasn't started yetI tried to exclude the Output line , and when i do it does run CMD but does not type in any command (It just opens a CMD window and does nothing ) .
Managed to do it in the End with .
Process.Start()
asynchronously starts a new process. When you get to theprocess.StandardOutput.ReadToEnd()
the process is not finished yet, thus the exception. You should use eventing to hook into the OutputDataRecieved event. You want to do something like this:and then add an event handler to the Output data recieved like so:
Also, I am not certain but i think you need to call text on your textboxes: