nairware nairware - 1 month ago 9
Python Question

7zip Commands from Python

There is a post on this topic already, but it does not have an explicit answer to the fundamental question which I am re-asking here:

How do you make 7zip commands from Python?

Attempting to use the subprocess module, I implemented the following which runs but does nothing (from what I can tell):

import subprocess
cmd = ['7z', 'a', '"Test.7z"', '"Test"', '-mx9']
subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)


I know that the following 7zip command works, as I have tested on the Windows command line itself:

7z a "Test.7z" "Test" -mx9


How could I implement that simple 7zip command from Python?

Answer
import subprocess
cmd = ['7z', 'a', 'Test.7z', 'Test', '-mx9']
sp = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)