Reputation: 13
I have a Visual Studio 2015 program that calls a command prompt. How do I write 2 lines to the command prompt? This is my current code:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C copy " + calibrT1 + "_CDF.hex\"" + calibrT1 + "_ECC_CDF.hex\"";
process.StartInfo = startInfo;
process.Start();
startInfo.Arguments = "/C c:\\ti\\hercules\\nowECC\\2.21.00\\nowECC -f035 -r4 -i "+ calibrT1 + "_ECC_CDF.hex\" -a ";
//MessageBox.Show("Tester");
process.StartInfo = startInfo;
process.Start();
As an interesting note. This current code does not work. However if the MessageBox.Show("Tester") is not commented out it does work. As such I can determine my lines of code are correct and work as I wish, however do not work sequentially without the MessageBox. I can't work out why as I can see no logical reason why a message box should effect my command prompt.
Thanks for any help.
Upvotes: 1
Views: 103
Reputation: 2468
You need to wait before starting the new one. So need to put WaitForExit before (this does the job that the MessageBox was doing).
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C copy " + calibrT1 + "_CDF.hex\"" + calibrT1 + "_ECC_CDF.hex\"";
process.StartInfo = startInfo;
process.Start();
process.WaitForExit(); // Wait First
startInfo.Arguments = "/C c:\\ti\\hercules\\nowECC\\2.21.00\\nowECC -f035 -r4 -i "+ calibrT1 + "_ECC_CDF.hex\" -a ";
process.StartInfo = startInfo;
process.Start();
Upvotes: 1