请问如何在startinfo.Arguments 里设置多条命令,比如我第一条命令是把文件打包成RAR,第二条命令再添加注释,怎么实现?
string rarexe; //WinRAR.exe 的完整路径
RegistryKey regkey; //注册表键
Object regvalue; //键值
string cmd; //WinRAR 命令参数
ProcessStartInfo startinfo;
Process process;
try
{
regkey = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\shell\open\command");
regvalue = regkey.GetValue(""); // 键值为 "d:\Program Files\WinRAR\WinRAR.exe" "%1"
rarexe = regvalue.ToString();
regkey.Close();
rarexe = rarexe.Substring(1, rarexe.Length - 7); // d:\Program Files\WinRAR\WinRAR.exe //Directory.CreateDirectory(path);
//压缩命令,相当于在要压缩的文件夹(path)上点右键->WinRAR->添加到压缩文件->输入压缩文件名(rarName)
cmd = string.Format(" a -df {0} {1} ", rarName, filname);
//在这里我怎么实现,再执行添加注册进RAR,若下面这行用cmd+=的话WINRAR的进程就无法关闭,程序就不能返回结果。怎么让startinfo.Arguments执行多条命令
// cmd = string.Format(" c -z{0} {1} ", HttpContext.Current.Server.MapPath("~") + notepath, rarName); startinfo = new ProcessStartInfo();
startinfo.FileName = rarexe;
startinfo.Arguments = cmd; //设置命令参数
startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隐藏 WinRAR 窗口 startinfo.WorkingDirectory = rarPath;
process = new Process();
process.StartInfo = startinfo;
process.Start();
process.WaitForExit(); //无限期等待进程 winrar.exe 退出 if (process.HasExited)
{
flag = true;
}
process.Close();
}
catch (Exception e)
{
throw e;
}
string rarexe; //WinRAR.exe 的完整路径
RegistryKey regkey; //注册表键
Object regvalue; //键值
string cmd; //WinRAR 命令参数
ProcessStartInfo startinfo;
Process process;
try
{
regkey = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\shell\open\command");
regvalue = regkey.GetValue(""); // 键值为 "d:\Program Files\WinRAR\WinRAR.exe" "%1"
rarexe = regvalue.ToString();
regkey.Close();
rarexe = rarexe.Substring(1, rarexe.Length - 7); // d:\Program Files\WinRAR\WinRAR.exe //Directory.CreateDirectory(path);
//压缩命令,相当于在要压缩的文件夹(path)上点右键->WinRAR->添加到压缩文件->输入压缩文件名(rarName)
cmd = string.Format(" a -df {0} {1} ", rarName, filname);
//在这里我怎么实现,再执行添加注册进RAR,若下面这行用cmd+=的话WINRAR的进程就无法关闭,程序就不能返回结果。怎么让startinfo.Arguments执行多条命令
// cmd = string.Format(" c -z{0} {1} ", HttpContext.Current.Server.MapPath("~") + notepath, rarName); startinfo = new ProcessStartInfo();
startinfo.FileName = rarexe;
startinfo.Arguments = cmd; //设置命令参数
startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隐藏 WinRAR 窗口 startinfo.WorkingDirectory = rarPath;
process = new Process();
process.StartInfo = startinfo;
process.Start();
process.WaitForExit(); //无限期等待进程 winrar.exe 退出 if (process.HasExited)
{
flag = true;
}
process.Close();
}
catch (Exception e)
{
throw e;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货