来自 Python 的 7zip 命令 [英] 7zip Commands from Python

查看:34
本文介绍了来自 Python 的 7zip 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经有一个关于这个主题的帖子,但它没有明确回答我在这里重新提出的基本问题:

There is a post on this topic already, but it does not have an explicit answer to the fundamental question which I am re-asking here:

如何从 Python 生成 7zip 命令?

How do you make 7zip commands from Python?

尝试使用 subprocess 模块,我实现了以下内容运行但什么也不做(据我所知):

Attempting to use the subprocess module, I implemented the following which runs but does nothing (from what I can tell):

import subprocess
cmd = ['7z', 'a', '"Test.7z"', '"Test"', '-mx9']
subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

我知道以下 7zip 命令有效,因为我已经在 Windows 命令行本身上进行了测试:

I know that the following 7zip command works, as I have tested on the Windows command line itself:

7z a "Test.7z" "Test" -mx9

我怎样才能从 Python 中实现那个简单的 7zip 命令?

How could I implement that simple 7zip command from Python?

推荐答案

import subprocess
cmd = ['7z', 'a', 'Test.7z', 'Test', '-mx9']
sp = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

这篇关于来自 Python 的 7zip 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆