【发布时间】:2013-06-14 11:19:24
【问题描述】:
我正在该应用程序中开发一个 Windows 应用程序,我使用 winrar 命令行实用程序制作 rar 文件。
代码
public static string RarFiles(string rarPackagePath,
Dictionary<int, string> accFiles)
{
string error = "";
try
{
string[] files = new string[accFiles.Count];
int i = 0;
foreach (var fList_item in accFiles)
{
files[i] = "\"" + fList_item.Value;
i++;
}
string fileList = string.Join("\" ", files);
fileList += "\"";
System.Diagnostics.ProcessStartInfo sdp = new System.Diagnostics.ProcessStartInfo();
string cmdArgs = string.Format("A {0} {1} -ep1 -r",
String.Format("\"{0}\"", rarPackagePath),
fileList);
sdp.ErrorDialog = true;
sdp.UseShellExecute = true;
sdp.Arguments = cmdArgs;
sdp.FileName = winrarPath;//Winrar.exe path
sdp.CreateNoWindow = false;
sdp.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process process = System.Diagnostics.Process.Start(sdp);
process.WaitForExit();
//string s = process.StandardOutput.ReadToEnd();
error = "OK";
}
catch (Exception ex)
{
error = ex.Message;
}
return error;
}
谁能告诉我如何处理winrar诊断信息。
【问题讨论】:
-
为什么要注释掉string s中保存标准输出的那一行?应该存储来自 winRar 的所有输出。
-
因为字符串 s 总是空白。当使用 winrar.exe 制作 rar 时出现错误时,它会显示诊断消息并且在 process.StandardOutput.ReadToEnd() 中不返回任何内容;
标签: c# winforms process winrar