如何从Windows窗体应用程序向cmd发送多个命令 [英] How to send multiple commands to cmd from windows form application

查看:130
本文介绍了如何从Windows窗体应用程序向cmd发送多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开命令提示符,并在C#中从Windows窗体应用程序点击按钮时自动发送多个命令作为参数。这里不是单个命令,而是希望将多个命令逐个发送到同一个命令提示符。在此先感谢。

I want to open command prompt and auto send multiple commands as arguments on button click from windows form application in C#. Here instead of single command I want to send multiple commands one by one to same command prompt. Thanks in advance.

推荐答案

假设您的应用程序支持从标准输入读取命令,只需使用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.


这篇关于如何从Windows窗体应用程序向cmd发送多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆