且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Windows窗体应用程序向cmd发送多个命令

更新时间:2023-12-06 10:33:04

假设您的应用程序支持从标准输入读取命令,只需使用Process.StandardInput.WriteLine [ ^ ]发送新命令。 />


您将无法等待退出 - 只有在命令处理器退出时才会出现,并且在此之后您无法执行任何有用的操作。 />


如果你要做的是排队windows命令一个接一个地执行,那么考虑写一个.BAT文件并执行它。批处理文件可以检查是否成功,如果需要,可以选择继续或失败。
Assuming that your application supports reading the commands from the standard input, just use Process.StandardInput.WriteLine[^] to "send" new commands.

You won't be able to wait for exit though - that only occurs when the command processor exits, and you can't do anything useful with it after that.

If what you are trying to do is "queue up" windows commands to be executed one after the other, then consider writing a .BAT file and executing that instead. The batch file can check for success / fail and optionally continue or fail if you need it to.