gpt4 book ai didi

c# - 无法使用 7-Zip 压缩标准输入并使用标准输出输出?

转载 作者:行者123 更新时间:2023-12-05 01:22:08 25 4
gpt4 key购买 nike

我收到错误消息“未实现”。

我想使用 7-Zip 压缩文件通过 stdin 然后通过 stdout 获取数据并使用我的应用程序进行更多转换。在man page它显示了这个例子:

% echo foo | 7z a dummy -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)其他东西。

最佳答案

您可能想尝试像 SevenZipSharp http://www.codeplex.com/sevenzipsharp 这样的东西,我个人从未使用过它,但它提供了 7za.dll COM 库的包装器,可能对您有所帮助。

我自己编写了通过进程使用 7-Zip 的实用程序,虽然我从未尝试执行 StdIn 和 StdOut 操作,但没有遇到任何问题。在我的 7-Zip 版本的帮助文件中,-si 开关状态的页面:

Note: The current version of 7-Zip does not support reading of archives from stdin.

请注意确定这是否可能是您的问题的根源,同时指定这两个开关可能会混淆 7-Zip。

他们在帮助中显示的示例似乎表明 -so 用于将输出重定向到标准输出,但需要基于普通文件的输入才能这样做。

关于c# - 无法使用 7-Zip 压缩标准输入并使用标准输出输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1287383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com