使用python运行bash脚本 - TypeError:bufsize必须是整数

Or *_*ith 13 python bash subprocess

我正在尝试编写python文件,这是python中的wxtrac tar文件.

据我所知,这subprocess是完成这项任务的合适工具.

我写下面的代码:

from subprocess import call


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


if __name__ == "__main__":
    tarfile("/root/tryit/output.tar")
Run Code Online (Sandbox Code Playgroud)

当输出是位于的tar文件时/root/tryit/.

当我运行它时,我收到以下消息:

TypeError: bufsize must be an integer
Run Code Online (Sandbox Code Playgroud)

我可以在这个工具中使用tar命令吗?

fal*_*tru 25

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

def tarfile(path):
    call(["tar", "xvf", path])
Run Code Online (Sandbox Code Playgroud)

顺便说一句,Python有一个tarfile模块:

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