using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;//加入,使用进程类,创建独立进程
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//实例一个process类
Process process = new Process();
//设定程序名
process.StartInfo.FileName = "cmd.exe";
//关闭Shell的使用
process.StartInfo.UseShellExecute = false;
//重新定向标准输入,输入,错误输出
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
//设置cmd窗口不显示
process.StartInfo.CreateNoWindow = true;
//开始
process.Start();
//输入命令,退出
process.StandardInput.WriteLine("ping 192.168.0.1");
//process.StandardInput.WriteLine("netstat");
process.StandardInput.WriteLine("exit");
//获取结果
string strRst = process.StandardOutput.ReadToEnd();
//显示结果到RichTextBox
this.richTextBox1.Text = strRst;
}
{
//实例一个process类
Process process = new Process();
//设定程序名
process.StartInfo.FileName = "cmd.exe";
//关闭Shell的使用
process.StartInfo.UseShellExecute = false;
//重新定向标准输入,输入,错误输出
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
//设置cmd窗口不显示
process.StartInfo.CreateNoWindow = true;
//开始
process.Start();
//输入命令,退出
process.StandardInput.WriteLine("ping 192.168.0.1");
//process.StandardInput.WriteLine("netstat");
process.StandardInput.WriteLine("exit");
//获取结果
string strRst = process.StandardOutput.ReadToEnd();
//显示结果到RichTextBox
this.richTextBox1.Text = strRst;
}
//我对这个的扩展
private void CallExeTest(string argm)//调用CMD命令提示符
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//关闭Shell的使用
p.StartInfo.UseShellExecute = false;
//重新定向标准输入,输入,错误输出
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
//设置cmd窗口不显示
p.StartInfo.CreateNoWindow = true;
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
//关闭Shell的使用
p.StartInfo.UseShellExecute = false;
//重新定向标准输入,输入,错误输出
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
//设置cmd窗口不显示
p.StartInfo.CreateNoWindow = true;
string str = "cd " +@"D:/DesignArea/衡水项目/TransformSystem/SchedulerServer/bin/Debug";
p.Start();
p.StandardInput.WriteLine(@"cd D:/Program Files/Microsoft Visual Studio .NET 2003/Common7/Tools/");
p.StandardInput.WriteLine("d:");
p.StandardInput.WriteLine("vsvars32.bat");
p.StandardInput.WriteLine(str);
p.StandardInput.WriteLine("installutil.exe SchedulerServer.exe");
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
p.Close();
//MessageBox.Show(strRst);
}
}
}