从我可以收集到的信息来看,您不能同时使用该
zip命令,这意味着您既不能指定文件名也不能通过管道传递内容。您可以通过管道传输内容,结果文件为
-,也可以通过管道传输文件名
-@。
这并不意味着使用其他技术是不可能的。我概述了以下内容之一。这确实意味着您必须安装PHP并加载zip扩展。
可能还有很多其他方式可以做到这一点。但这是我所知道的最简单的方法。哦,那也是单线的。
这是使用PHP的有效示例
echo contents | php -r '$z = new ZipArchive();$z->open($argv[1],ZipArchive::CREATE);$z->addFromString($argv[2],file_get_contents("php://stdin"));$z->close();' test.zip testfile要在Windows上运行,只需交换单引号和双引号。或者只是将脚本放在文件中。
“ test.zip”是生成的Zip文件,“ testfile”是正在传递到命令中的内容的名称。
结果来自
unzip -l test.zip
Archive: test.zip Length Date Time Name--------- ---------- ----- ---- 6 01-07-2010 12:56 testfile--------- ------- 6 1 file
这是一个使用python的工作示例
echo contents | python -c "import sysimport zipfilez = zipfile.ZipFile(sys.argv[1],'w')z.writestr(sys.argv[2],sys.stdin.read())z.close()" test5.zip testfile2
的结果
unzip -l
Archive: test5.zip Length Date Time Name -------- ---- ---- ---- 9 01-07-10 13:43 testfile2 -------- ------- 9 1 file
的结果
unzip -p
contents



