如何通过 VB.Net 运行输入 Cmd 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21971025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Run Input Cmd Commands By VB.Net
提问by Al-Mobarmge
I have a problem with CMD in a VB.NET project I'm making. How can I input three different commands to the same CMD window I open through a Button on my Form. Whenever I click the button on my form I want the CMD window to open, execute the first command and then automatically proceed to execute the next command and so on.
我在制作的 VB.NET 项目中遇到 CMD 问题。如何将三个不同的命令输入到我通过表单上的按钮打开的同一个 CMD 窗口。每当我单击表单上的按钮时,我都希望 CMD 窗口打开,执行第一个命令,然后自动继续执行下一个命令,依此类推。
The three commands must be run in the same sequence in order to do its job.
这三个命令必须以相同的顺序运行才能完成其工作。
The code I used:
我使用的代码:
Process.start ("cmd","/k First Code " & "Second Code " & "Third Code")
回答by Derek
You could write out a batch file to disk and then run the batch file.
您可以将批处理文件写入磁盘,然后运行该批处理文件。
Also see: How to run two commands in one line in Windows CMD?
另请参阅: 如何在 Windows CMD 中的一行中运行两个命令?
It looks like you can use & to separate commands.
看起来您可以使用 & 来分隔命令。
I'd do something like:
我会做这样的事情:
Process.Start(String.Format("cmd /k {0} & {1} & {2}", "First Code", "Second Code", "Third Code"))
This might work better: (as an example)
这可能会更好:(例如)
Process.Start("cmd", String.Format("/k {0} & {1} & {2}", "dir c:", "dir /w c:", "pause"))
You can substitute your own commands in here.
您可以在此处替换您自己的命令。
回答by Al-Mobarmge
I Found the correct Code yesterday Thanks for the Replys the Correct code that works for me is
我昨天找到了正确的代码 感谢您的回复 对我有用的正确代码是
Process.start ( "cmd" , "/k First code second code -c Third Code " )
Thanks for the Replays
感谢重播