1

I am trying to extract a .tgz file by calling 7-zip using the subprocess function (helpful stack overflow post here)

I need to call subprocess twice. First to unzip from .tgz --> .tar and second to unzip from .tar --> .txt

My code successfully unzips the first step, but nothing happens on the second step, any ideas why?

subprocess.Popen([r'C:\Program Files\7-Zip\7z.exe', 'e', '-y', '-r', '-o' + pth, os.path.join(root, 'myZip.tgz')])
subprocess.Popen([r'C:\Program Files\7-Zip\7z.exe', 'e', '-y', '-r', '-o' + pth, os.path.join(pth, 'myZip.tar')])

"pth" is the output path and "root" is the path where the original zipped file is. I opened up the pth folder and there is in fact a myZip.tar file there.

mfgeng
  • 89
  • 5

1 Answers1

0

Popen() is a non-blocking call that starts the other process but does not wait for it to finish. You need to wait for the first call to finish before making the second call to guarantee that the .tar file is present.

drootang
  • 2,351
  • 1
  • 20
  • 30