代码之家  ›  专栏  ›  技术社区  ›  user3725561

subprocess.call和tar-zxvf

  •  0
  • user3725561  · 技术社区  · 11 年前

    我正在尝试调用此命令 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)
    

    有什么帮助吗?谢谢

    1 回复  |  直到 11 年前
        1
  •  4
  •   Ashoka Lella    11 年前

    可以使用 tarfile 单元

    import tarfile
    tar = tarfile.open("sample.tar.gz")
    tar.extractall()
    tar.close()