无法使用 7-Zip 压缩标准输入并使用标准输出输出?
我收到错误“未实施”。
我想通过标准输入使用 7-Zip 压缩文件,然后通过标准输出获取数据并使用我的应用程序进行更多转换。 在手册页中显示了以下示例:
% echo foo | 7z 虚拟-tgzip -si -so > /dev/null
我正在使用 Windows 和 C#。
结果:
7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03
Creating archive StdOut
System error:
Not implemented
代码:
public static byte[] a7zipBuf(byte[] b)
{
string line;
var p = new Process();
line = string.Format("a dummy -t7z -si -so ");
p.StartInfo.Arguments = line;
p.StartInfo.FileName = @"C:\Program Files\7-Zip\7z.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.BaseStream.Write(b, 0, b.Length);
p.StandardInput.Close();
Console.Write(p.StandardError.ReadToEnd());
//Console.Write(p.StandardOutput.ReadToEnd());
return p.StandardOutput.BaseStream.ReadFully();
}
是否有另一种简单的方法将文件读入内存?
现在我可以1)写入临时文件并读取(简单并且可以复制/粘贴一些代码)2)使用文件管道(中?我从来没有这样做过)3)其他东西。
I get the error "Not implemented".
I want to compress a file using 7-Zip via stdin then take the data via stdout and do more conversions with my application. In the man page it shows this example:
% echo foo | 7z a dummy -tgzip -si -so > /dev/null
I am using Windows and C#.
Results:
7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03
Creating archive StdOut
System error:
Not implemented
Code:
public static byte[] a7zipBuf(byte[] b)
{
string line;
var p = new Process();
line = string.Format("a dummy -t7z -si -so ");
p.StartInfo.Arguments = line;
p.StartInfo.FileName = @"C:\Program Files\7-Zip\7z.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.BaseStream.Write(b, 0, b.Length);
p.StandardInput.Close();
Console.Write(p.StandardError.ReadToEnd());
//Console.Write(p.StandardOutput.ReadToEnd());
return p.StandardOutput.BaseStream.ReadFully();
}
Is there another simple way to read the file into memory?
Right now I can 1) write to a temporary file and read (easy and can copy/paste some code) 2) use a file pipe (medium? I have never done it) 3) Something else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能想尝试诸如 SevenZipSharp http://www.codeplex.com/sevenzipsharp 之类的东西,我我个人从未使用过它,但它提供了 7za.dll COM 库的包装器,这可能对您有帮助。
我自己编写了通过进程使用 7-Zip 的实用程序,尽管我从未尝试过执行 StdIn 和 StdOut 操作,但没有遇到任何问题。 在我的 7-Zip 版本的帮助文件中,-si 开关上的页面指出:
请注意,确定这是否可能是问题的根源,指定这两个开关可能会使 7-Zip 感到困惑。
他们在帮助中显示的示例似乎表明 -so 用于将输出重定向到标准输出,但需要基于普通文件的输入才能执行此操作。
You might want to try out something like SevenZipSharp http://www.codeplex.com/sevenzipsharp, I've never used it personally but it provides a wrapper to the 7za.dll COM library which may be helpful to you.
I've written utilities that utilise 7-Zip via a process myself and haven't had issues though I've never tried to do StdIn and StdOut stuff. In the Help files I have with my version of 7-Zip the page on the -si switch states:
Note sure if this might be the source of your problem, with specifying both switches it might be confusing 7-Zip.
The examples they show in the help seem to show that -so is used to redirect the output to standard out but requires normal file based inputs to do so.
以下是 Igor Pavlov(7z 的作者)在关于 "7zip as 的主题中提供的一些信息gzip/bzip2 的直接替代品?”
建议基本上使用 7z 作为
xz
代理。 仅使用 xz 应该可以,但它可能不是多线程的(7z 可能是)。在尝试使用 7z 时,如下所示:
Igor Pavlov 说:
并且
最终的解决方案是:
错误报告建议这应该在帮助中:
Here's some info from Igor Pavlov (7z's author), in a thread about "7zip as a drop-in replacement for gzip/bzip2?"
The suggestion was to basically use 7z as an
xz
surrogate. Just usingxz
should work, but it may not be multi-threaded (and 7z may be).While attempting to use 7z as in:
Igor Pavlov says:
And
The eventual solution was:
A bug report suggests this should be in the help:
当将
stdout
通过管道传输到7zip
时,我遇到了类似的问题,而不是直接从
Process
调用命令,而是将命令写入批处理文件,然后然后运行批处理文件。 这是一个黑客,但它确实有效。I ran into a similar problem when piping
stdout
into7zip
Instead of invoking the command from
Process
directly, I write the command to a batch file and then run the batch file. It's a hack, but it does work.您可能需要使用
7za.exe
,它是 7z 下载页面。 我发现您当前正在使用7z.exe
,并且我很确定这也是我以前遇到过的问题。Actually, I think I switched to PeaZip because of the troubles 7z was giving me. PeaZip is a wrapper around 7z and a few other compression utilities, and PeaZip has a little bit better command line interface.
You might need to use
7za.exe
, which is the "Commandline version" on the 7z download page. I see that you are currently using7z.exe
, and I'm pretty sure that's a problem I've encountered before as well.Actually, I think I switched to PeaZip because of the troubles 7z was giving me. PeaZip is a wrapper around 7z and a few other compression utilities, and PeaZip has a little bit better command line interface.
最简单的方法是使用
xz
,它默认使用与 7-zip 相同的压缩算法,并带有-T0
参数,这使得xz
> 多线程自动缩放至 CPU 核心数量,速度与 7-zip 一样快。一些命令 | xz-T0> 一些_文件.xz
The simplest way is to use
xz
, which by default uses the same compression algorithm as 7-zip, with the-T0
param, which makesxz
multithreaded scaling to the number of your CPU cores automatically, and as fast as 7-zip.some_command | xz -T0 > some_file.xz