C# 怎么调用CMD.bat执行命令过程显示在listbox呀?
有button1 button2 怎么能分别运行1.bat 2.bat 并且过程都分别显示在listbox?并且有个textbox 用户输入指令后xxxxx 点击button3能运行cmd并且显示在listbox?
新手初学 求帮助~~ --------------------编程问答-------------------- private void button1_Click(object sender,EventArgs e)
{
Process.Start("cmd.exe","1.bat");
listBox1.Add("运行了1.bat");
}
private void button2_Click(object sender,EventArgs e)
{
Process.Start("cmd.exe","2.bat");
listBox1.Add("运行了2.bat");
}
private void button3_Click(object sender,EventArgs e)
{
Process.Start("cmd.exe",textbox.Text);
listBox1.Add("运行了" + textbox.Text + "指令");
} --------------------编程问答--------------------
private void button1_Click(object sender, EventArgs e)--------------------编程问答-------------------- 有没有办法调用外部的1.bat文件 不需要在C#中执行 只要能1.bat执行窗口嵌入form1窗体的某个位置
{
string str = textBox1.Text;
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.WriteLine(str);
myStreamWriter.Close();
string s = myProcess.StandardOutput.ReadToEnd();
MessageBox.Show(s);
}
补充:.NET技术 , C#