程序如下,和网上的一样:
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.StandardInput.WriteLine("D:");
p.WaitForExit();
p.Close();
启动调试后Cmd打开但什么内容都没有,也不能输入,只能关闭。把p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;全部删掉才行,但p.StandardInput.WriteLine("D:");就无效了。删掉两条中的一条Cmd程序闪一下就自动关闭了。
请高手指教是怎么回事?
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.StandardInput.WriteLine("D:");
p.WaitForExit();
p.Close();
启动调试后Cmd打开但什么内容都没有,也不能输入,只能关闭。把p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;全部删掉才行,但p.StandardInput.WriteLine("D:");就无效了。删掉两条中的一条Cmd程序闪一下就自动关闭了。
请高手指教是怎么回事?
http://www.haoxiai.net/wangzhanzhizuo/aspnet/53727.html
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true; process.Start();
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("exit");
process.Close();
private void ViewInfotbn_Click(object sender, EventArgs e)
{
this.ViewInfotbn.Enabled = false;
/*
ProcessStartInfo start = new ProcessStartInfo("cmd.exe");//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
//如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
//start.Arguments = "192.168.0.179";//设置命令参数
start.CreateNoWindow = true;//不显示dos命令行窗口
start.RedirectStandardOutput = true;//
start.RedirectStandardInput = true;//
start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
Process p = Process.Start(start);
StreamReader reader = p.StandardOutput;//截取输出流
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)
{
this.ViewInfoRTB.AppendText(line + "\n\n");
line = reader.ReadLine();
}
p.WaitForExit();//等待程序执行完退出进程
p.Close();//关闭进程
reader.Close();//关闭流*/ Process p = new Process();
p.StartInfo.FileName = "系统大扫除.bat";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;//true表示不显示黑框,false表示显示dos界面 p.Start();
// p.StandardInput.WriteLine("系统大扫除.bat");
//p.StandardInput.WriteLine("exit");
StreamReader reader = p.StandardOutput;
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)
{
this.ViewInfoRTB.AppendText(line + "\n");
//this.ViewInfoRTB.AppendText("\n"); line = reader.ReadLine();
}
p.WaitForExit();
p.Close();
reader.Close();
this.ViewInfoRTB.AppendText("系统垃圾文件已清理完毕!");
}以上源代码是在如下项目中经过检验了的,你可以下载体会一下。
【如果我的回答对你有所帮助,请到下列地址http://download.csdn.net/source/2247484 下载原创家庭记账软件,并给出宝贵意见!】
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true; process.Start();
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("exit");
process.Close();
就是这个啊
一句代码搞定
System.Diagnostics.Process.Start("cmd");