使用 python 运行 bash 脚本 - TypeError: bufsize must be an integer
·
回答问题
我正在尝试编写 python 文件,即 python 中的 wxtrac tar 文件。
据我了解,subprocess是完成此任务的合适工具。
我写了以下代码:
from subprocess import call
def tarfile(path):
call(["tar"], path)
if __name__ == "__main__":
tarfile("/root/tryit/output.tar")
当输出是 tar 文件时,它位于/root/tryit/。
当我运行它时,我收到以下消息:
TypeError: bufsize must be an integer
我可以用这个工具使用 tar 命令吗?
Answers
您应该将命令指定为列表。除此之外,缺少主要选项(x)。
def tarfile(path):
call(["tar", "xvf", path])
顺便说一句,Python 有一个tarfile模块:
import tarfile
with tarfile.open("/root/tryit/output.tar") as tar:
tar.extractall() # OR tar.extractall("/path/to/extract")
更多推荐

所有评论(0)