我正在尝试编写 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/