简体   繁体   English

Visual Studio 2015 命令提示符问题

[英]Visual Studio 2015 Command Prompt issues

I have a Visual Studio 2015 program that calls a command prompt.我有一个调用命令提示符的 Visual Studio 2015 程序。 How do I write 2 lines to the command prompt?如何在命令提示符中写入 2 行? 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.但是,如果 MessageBox.Show("Tester") 没有被注释掉,它确实有效。 As such I can determine my lines of code are correct and work as I wish, however do not work sequentially without the MessageBox.因此,我可以确定我的代码行是正确的并且可以按我的意愿工作,但是如果没有 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.谢谢你的帮助。

You need to wait before starting the new one.在开始新的之前,您需要等待。 So need to put WaitForExit before (this does the job that the MessageBox was doing).所以需要把 WaitForExit 放在之前(这完成了 MessageBox 正在做的工作)。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM