如何处理来自代码的winrar诊断消息
本文关键字:代码 winrar 诊断 消息 何处理 处理 | 更新日期: 2023-09-27 18:18:18
我正在开发一个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;
}
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诊断信息
我认为你遗漏了一些部分:
试着添加这些:
sdp.StartInfo.RedirectStandardOutput = true;
在Start之后,添加一个字符串来获得输出。之后,调用WaitForExit()
sdp.Start();
string output = stillc.StandardOutput.ReadToEnd();
sdp.WaitForExit();
*注意:此操作仅在控制台窗口中显示输出时有效。
希望有帮助