不知道楼主的输入参数是做什么用的,首先设计是不是合理。 如果输入的参数是为C#程序代码服务的,那我就晕了,为什么要这样设计;如果是为批处理服务的,那么楼主的批处理应该可以接收参数啊。@echo off echo 请输入您的目标IP代号 (0、退出 1、公司 2、家) set /p IP=请输入(数字): echo if %IP%==2 goto home ...单纯的使用process是无法hold住cmd窗口的,pause能hold住但不是等待用户输入的。
Process p = new Process(); p.StartInfo.FileName = "C:\\windows\\System32\\cmd.exe"; p.Start(); Thread.Sleep(1000); SendKeys.Send("e:\\aaa.bat"); SendKeys.Send("{Enter}"); p.WaitForExit();这样可以吗?执行了你要的BAT之后窗口还在,你再将p的输出信息Redirect到你的TextBox中就好了。
窗口停在那,等待我输入
using (Process myCommand = new Process())
{
myCommand.StartInfo.FileName = commandPath;
myCommand.StartInfo.RedirectStandardOutput = true;
myCommand.StartInfo.UseShellExecute = false;
myCommand.Start();
Console.WriteLine(myCommand.StandardOutput.ReadToEnd());
}
Console.Read();
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"C:\Windows\System32\cmd.exe";
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
info.Arguments = @"/c C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:library " + path + @"\a.cs /r:"+ Assembly.GetExecutingAssembly().Location+@" >E:\out.txt";
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit();
info.Arguments = @"/c C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:library " + path + @"\a.cs /r:"+ Assembly.GetExecutingAssembly().Location+@" >E:\out.txt";这个看不懂...我是执行一个批处理啊。。
明白了,貌似要用回调,我再仔细看一下msdn
System.Diagnostics.Process.Start("cmd.exe");
{
Process p = new Process();
p.StartInfo.FileName = "ftp.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.StandardInput.WriteLine("help");
p.StandardInput.WriteLine("quit");
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
MessageBox.Show(output);
}
我用你的试了一下,只弹出了run.bat里面的信息,而clearlocks -verbose执行的信息没有...
如果输入的参数是为C#程序代码服务的,那我就晕了,为什么要这样设计;如果是为批处理服务的,那么楼主的批处理应该可以接收参数啊。@echo off
echo 请输入您的目标IP代号 (0、退出 1、公司 2、家)
set /p IP=请输入(数字):
echo
if %IP%==2 goto home
...单纯的使用process是无法hold住cmd窗口的,pause能hold住但不是等待用户输入的。
p.StartInfo.FileName = "C:\\windows\\System32\\cmd.exe";
p.Start();
Thread.Sleep(1000);
SendKeys.Send("e:\\aaa.bat");
SendKeys.Send("{Enter}");
p.WaitForExit();这样可以吗?执行了你要的BAT之后窗口还在,你再将p的输出信息Redirect到你的TextBox中就好了。
cmd有一个参数/k...
具体用法自己打cmd /?看.