Reputation: 7505
I'm trying to create a series of tar files from within Python code. As a practice I have a subdirectory - 'O', which contains the files I want to tar. When I try typing
tar -cf O.tar ./O
from the command line, things work. But, when I enter the Python interpreter and enter
import subprocess
subprocess.call(["tar","-cf O.tar ./O"])
I get the following error:
tar: Cowardly refusing to create an empty archive
Does this make sense? I tried
import os
os.listdir(".")
To make sure I could still see my "O" subdirectory from within the Python shell, and I can.
What am I missing here?
Upvotes: 0
Views: 776
Reputation:
it will work run:
import subprocess
import sys
proc = subprocess.Popen(["tar","-cf O.tar ./O"],stdin=subprocess.PIPE)
proc.communicate()
if you can execute some other command or program use sys.executeable()
Upvotes: -1
Reputation: 1946
maybe.
import subprocess
subprocess.call(["tar","-cf", "O.tar", "./O"])
Upvotes: 3