我试图从 python 脚本调用此命令 tar -zxvf file.tar.gz
但我遇到了问题。我已经阅读了一些相关的问答,但我仍然不知道该怎么做。
我在考虑让我的代码适合原始命令:
subprocess.check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
目前我已经做了几次尝试,如下图
stdin = file.tar.gz
subprocess.check_call(-zxvf, stdin)
有什么帮助吗?谢谢。
最佳答案
您可以使用tarfile
模块解压文件
import tarfile
tar = tarfile.open("sample.tar.gz")
tar.extractall()
tar.close()
关于python - subprocess.call 和 tar -zxvf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24799500/