[英]subprocess.call and tar -zxvf
I am trying to call this command tar -zxvf file.tar.gz
from a python script and I'm having trouble with it. 我正在尝试从python脚本调用此命令tar -zxvf file.tar.gz
,但遇到了麻烦。 I've read some relevant q/a's but I still haven't figured out how to do it. 我已经阅读了一些相关的问答,但是我仍然没有弄清楚该如何做。
I was thinking to fit my code to the original command: 我当时正在考虑使我的代码适合原始命令:
subprocess.check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
So far I've made several attempts, as shown below 到目前为止,我已经做了几次尝试,如下所示
stdin = file.tar.gz
subprocess.check_call(-zxvf, stdin)
Any help? 有什么帮助吗? Thanks. 谢谢。
You can untar a file using the tarfile
module 您可以使用tarfile
模块解压缩文件
import tarfile
tar = tarfile.open("sample.tar.gz")
tar.extractall()
tar.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.