gpt4 book ai didi

python - 使用 python 运行 bash 脚本 - TypeError : bufsize must be an integer

转载 作者:太空狗 更新时间:2023-10-29 17:25:52 25 4
gpt4 key购买 nike

我正在尝试编写 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 命令吗?

最佳答案

您应该将命令指定为列表。除此之外,缺少主要选项 (x)。

def tarfile(path):
call(["tar", "xvf", path])

顺便说一句,Python 有一个 tarfile module :

import tarfile
with tarfile.open("/root/tryit/output.tar") as tar:
tar.extractall() # OR tar.extractall("/path/to/extract")

关于python - 使用 python 运行 bash 脚本 - TypeError : bufsize must be an integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25977092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com