Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run bash script with python - TypeError: bufsize must be an integer

I'm trying to write python file, which wxtrac tar file in python.

As I understand, subprocess is the appropriate tool for this mission.

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/.

When I run it, i get the following message:

TypeError: bufsize must be an integer

Can I use tar command with this tool?

like image 209
Or Smith Avatar asked Sep 22 '14 14:09

Or Smith


1 Answers

You should specify the command as a list. Beside that, main option (x) is missing.

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

BTW, Python has a tarfile module:

import tarfile
with tarfile.open("/root/tryit/output.tar") as tar:
    tar.extractall()  # OR tar.extractall("/path/to/extract")
like image 191
falsetru Avatar answered Oct 13 '22 18:10

falsetru