p.StartInfo.FileName = "cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("jar cvf d:\xxx\xx.jar d:\xxx\xxx\");// 向cmd.exe输入command
p.StandardInput.WriteLine("exit");
p.WaitForExit(60000);
//string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
// MessageBox.Show(s);
p.Close();
p.Start();//目前的cmd路径是当前这个程序的路径我想执行我的语句之前把 目录换成 D:\xxx文件夹 怎么写?要不然 我每次压缩都要带上路径 郁闷。。
给位童鞋帮帮忙撒要给力(⊙o⊙)哦
System.IO.Directory.GetCurrentDirectory()
获取应用程序的当前工作目录。
System.AppDomain.CurrentDomain.BaseDirectory
获取程序的基目录。
System.Windows.Forms.Application.StartupPath
获取启动了应用程序的可执行文件的路径
p.Start();
p.StandardInput.WriteLine("D:");
p.StandardInput.WriteLine("cd smemo");
这样也不行。。
你把这一行注释了不就清楚了。调完了再
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = "D:\\XXX";//加上这句就ok了。。设置工作目录
p.Start();