c# 7za.exe 进程状态

标签 c# process progress 7zip

我正在运行一个 7za.exe 进程来 7zip 一个这样的文件:

ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = zip_Path;
proc.Arguments = "a -t7z ziped.7z file.bak";
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = true;
proc.UseShellExecute = false;
proc.CreateNoWindow = true;
p = Process.Start(proc); 
while (!p.HasExited)
{   
    res = p.StandardOutput.ReadLine();
    texto += "\n" + res;
}
 MessageBox.Show(texto + "\n" + "ErrorCode:" + p.ExitCode);
 p.Close();

这工作正常,但是当我在控制台上手动运行 7za.exe 时,我可以看到压缩进度。有什么办法可以在我的应用程序上实时输出吗?

最佳答案

我知道这是一个老问题,但我在这里找到了答案 https://stackoverflow.com/a/4291965/4050735

答案中的代码示例:

var proc = new Process {
StartInfo = new ProcessStartInfo {
    FileName = "program.exe",
    Arguments = "command line arguments to your executable",
    UseShellExecute = false,
    RedirectStandardOutput = true,
    CreateNoWindow = true
}

proc.Start();
while (!proc.StandardOutput.EndOfStream) {
    string line = proc.StandardOutput.ReadLine();
    // do something with line
}

我发现这会返回您通常会在控制台中看到的每一行,例如一次压缩一个文件的每个文件。

关于c# 7za.exe 进程状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10552544/

相关文章:

process - Erlang ETS 表与消息传递 : Optimization concerns?

scala - 是否有任何用于捕获外部进程输出的 Scala 内置类?

ios - 如何使用 PHAssetResourceRequestOptions progressHandler/PHAssetResourceProgressHandler

c# - 如何避免堆栈溢出?

c# - 特定范围内的随机数C#

c# - 应用程序因进程退出事件而退出

Java Sonatype 异步 HTTP 客户端上传进度

asp.net-mvc-4 - 当 FileResult 函数在 MVC4 中运行时如何显示 'in progress'

c# - Identity asp.net core 3.0 - 找不到IdentityDbContext

c# - 获取屏幕的真实尺寸