This article describes the way Python uses 7z to extract APK packets. Share to everyone for your reference. Specifically as follows:
This code is called 7z to decompress the APK package through the shell.
def run_shell (Command, Mayfreeze=false): Def check_retcode (Retcode, cmd): if 0!= retcode:print >> sys.stderr,
' Err executing ' + cmd + ': ', Retcode sys.exit (retcode) def read_close (f): F.seek (0) d = f.read () f.close () return D #print >> sys.stderr, '-Executing ', command if mayfreeze:tempout, Temperr = Tempfile. Temporaryfile (), Tempfile. Temporaryfile () #open (Os.devnull, ' w ') p = subprocess.
Popen (Command, Stdout=tempout, Stderr=temperr) p.wait () output, errout = Read_close (tempout), Read_close (temperr) Else: P=subprocess. Popen (command,stdout=subprocess. Pipe,stderr=subprocess. PIPE) output = P.stdout.read () p.wait () Errout = P.stderr.read () p.stdout.close () p.stderr.close () #check_retcode p. ReturnCode, command) return (Output.strip (), Errout.strip ()) #z7 are the full path to 7z.exe #at times you have to encode The command into Gbk/utf8 run_shell (U ' {0}-y-o ' {1} ' {2} x ' {3} '. Format (Z7, TempDir, Icon, apk)) shutil.copy (U ' {0}/{1} '. f Ormat (TEMPDIR,OS.PAth.basename (icon)), Dst_path
I hope this article will help you with your Python programming.