I have following simple python code that aims to minic
/usr/bin/tar -czvf x002.tgz *.py
The code is:
import subprocess
base_dir = "/home/workspace/x002"
tar_file = "x002.tgz"
py_file = "*.py"
p = subprocess.Popen(["/usr/bin/tar", "-czvf", tar_file, py_file], cwd=base_dir, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=False)
results = []
while True:
line = p.stdout.readline().decode('utf8').strip()
if line == '' and p.poll() is not None:
break
else:
results.append(line)
print(results)
I confirm that there exists py
files under the directory of base_dir
, but it complains as follows, I don't know where the problem is ,could someone help take a look? Thanks!
['tar: *.py: Cannot stat: No such file or directory', 'tar: Exiting with failure status due to previous errors', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']