使用 python 运行 bash 脚本 - TypeError: bufsize must be an integer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25977092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run bash script with python - TypeError: bufsize must be an integer
提问by Or Smith
I'm trying to write python file, which wxtrac tar file in python.
我正在尝试编写python文件,该文件是python中的wxtrac tar文件。
As I understand, subprocess
is the appropriate tool for this mission.
据我了解,subprocess
是执行此任务的合适工具。
I write the following code:
我写了以下代码:
from subprocess import call
def tarfile(path):
call(["tar"], path)
if __name__ == "__main__":
tarfile("/root/tryit/output.tar")
When output is the tar file, which located in /root/tryit/
.
当输出是 tar 文件时,它位于/root/tryit/
.
When I run it, i get the following message:
当我运行它时,我收到以下消息:
TypeError: bufsize must be an integer
Can I use tar command with this tool?
我可以在这个工具中使用 tar 命令吗?
回答by falsetru
You should specify the command as a list. Beside that, main option (x
) is missing.
您应该将命令指定为列表。除此之外,x
缺少主要选项 ( )。
def tarfile(path):
call(["tar", "xvf", path])
BTW, Python has a tarfile
module:
顺便说一句,Python 有一个tarfile
模块:
import tarfile
with tarfile.open("/root/tryit/output.tar") as tar:
tar.extractall() # OR tar.extractall("/path/to/extract")