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?
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With