I have a python script that should run 7z.exe with the command: "x" and switch " -o" using subprocess.run(). The script is as follows:
import subprocess as sb
zipperpath = "C:\\Program Files\\7-zip\\7z.exe"
dirname ="C:\\Users\\ajain\\Desktop\\TempData"
archivename="UnprocessedData_v3.7z"
outputfilename="foo"
sb.run([zipperpath,"x",os.path.join(dirname,archivename)," -o",os.path.join(dirname,outputfilename)])
Output is: Although the return code is 0, the zip never gets unzipped.
Try with this :
import subprocess
# variable cmd is is your command line , like you put in your console
cmd='7z.exe x UnprocessedData_v3.7z'
process = subprocess.Popen(cmd,shell=True,stdin=None,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
# The output from your shell command in an array
result=process.stdout.readlines()
if len(result) >= 1:
for line in result:
print(line)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.