我有一个python脚本,应使用命令“ x”运行7z.exe,并使用subprocess.run()切换“ -o”。脚本如下:
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)])
尝试一下:
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)