.NET程序页面中,操作并输入cmd命令的小例子
WinFormsApp_OperateAndInputCMD:
新建Form1,拖入TextBox,并设为允许多行,Dock设为Fill,然后绑定KeyUp事件即可
执行代码如下:
private void txtCmdInput_KeyUp(object sender, KeyEventArgs e){
if (e.KeyCode == Keys.Enter)
{
int count = txtCmdInput.Lines.Length;
if (count == 0) return;
while (count > 0 && (string.IsNullOrEmpty(txtCmdInput.Lines[count - 1])))
{
count--;
}
if (count > 0)// && !string.IsNullOrEmpty(txtCmdInput.Lines[count - 1]))
ExecuteCmd(txtCmdInput.Lines[count - 1]);
}
}
public void ExecuteCmd(string cmd)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start(); //设置自动刷新缓冲并更新
p.StandardInput.AutoFlush = true; //写入命令
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit"); //等待结束
txtCmdInput.AppendText(p.StandardOutput.ReadToEnd());
p.WaitForExit();
p.Close();
}
执行效果图:
- .NET程序页面中,操作并输入cmd命令
- C#根据域名查询IP(CMD命令参数输入或者启动程序后再输入查询)
- cmd窗口输入pip显示不是内部或外部命令,也不是可运行的程序或批处理文件的处理
- 在cmd输入命令符出现“不是内部或外部命令,也不是可运行的程序或批处理文件”的错误
- .Net程序操作CMD命令
- Python cmd中输入'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- 开始菜单中的“运行”是通向程序的快捷途径,输入特定的命令后,即可快速的打开Windows的大部分程序,熟练的运用它,将给我们的操作带来诸多便捷。 winver 检查Windows版本 wmimg
- 运行cmd,输入tracert,发现cmd提示,这不是可运行程序或命令或批处理文件
- Services开源框架之CXF与在java程序中如何实现操作cmd执行网络命令
- cmd下输入命令,控制台提示:“不是内部或外部命令,也不是可运行的程序或批处理文件”
- cmd输入命令报错“不是内部或外部命令,也不是可运行的程序或批处理文件”
- Python--到cmd中输入'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- Android在CMD中输入adb命令,提示“'adb' 不是内部或外部命令,也不是可运行的程序”的解决方法
- 调试时不用在cmd中输入命令参数,直接在属性页中操作
- WIN7的CMD界面下输入ipconfig后提示不是内部或外外部命令,也不是可运行的程序或批处理文件
- 在cmd(命令提示符)输入xxx命令后显示“xxx不是内部或者外部命令,也不是可运行程序或批处理文件”
- 本地msdos(cmd)下输入mysql命令提示:‘mysql’不是内部或外部命令,也不是可运行的程序或批处理文件
- Python--到cmd中输入'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- C#根据域名查询IP(CMD命令参数输入或者启动程序后再输入查询)
- 安装jdk后,在cmd中输入“javac”,出现“javac不是内部命令或外部命令,也不是可运行的程序或批处理文件”的解决方法