110,539
社区成员
发帖
与我相关
我的任务
分享
Process.StartInfo.UseShellExecute=false;
这一行代码去除后,可以打开文件出现如图所示的cmd窗口,因为我要输入命令,所以我得添加Process.StartInfo.UseShellExecute=false;
和p.StandardInput.WriteLine( "ru-standard");
代码,但是一旦我添加了这行代码,调试运行后会提示系统找不到文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string targetDir = string.Format(@"C:\MSC.Software\Adams\2013\common");
Process p = new Process(); // 初始化新的进程
p.StartInfo.WorkingDirectory = targetDir;
p.StartInfo.FileName = "mdi.bat";
p.StartInfo.RedirectStandardInput = true; //重定向输入
p.StartInfo.UseShellExecute = false; // 不调用系统的Shell
p.StartInfo.RedirectStandardError = true; // 重定向Error
p.Start(); // 启动进程
p.StandardInput.WriteLine( "ru-standard");
p.WaitForExit(); // 等待退出
}
}
static void Main(string[] args)
{
string targetDir = string.Format(@"D:\Test");
Process p = new Process(); // 初始化新的进程
p.StartInfo.WorkingDirectory = targetDir;
p.StartInfo.FileName = @"cmd.exe";
p.StartInfo.Arguments = @"/k D:\Test\run.bat";
p.StartInfo.RedirectStandardInput = true; //重定向输入
p.StartInfo.UseShellExecute = false; // 不调用系统的Shell
p.StartInfo.RedirectStandardError = true; // 重定向Error
p.Start(); // 启动进程
p.StandardInput.WriteLine("dir");
p.WaitForExit(); // 等待退出
}