[英]Run bash script with python - 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命令吗?
您应该将命令指定为列表。 除此之外,缺少主要选项( 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.