简体   繁体   中英

Reading terminal output in Python

I'm trying to open zip in terminal in python using subprocess, but I'm getting an error.

FileNotFoundError: [Errno 2] No such file or directory.

my purpose is to see if the process is successful or unsuccessful after opening the zip file and to print it.

Also my code:

from subprocess import run
output = run("unzip -P password /Users/username/Desktop/something.zip -d /Users/Desktop/Desktop/something", capture_output=True).stdout
print(output)

How can I fix the problem?

Change

output = run("unzip -P password /Users/username/Desktop/something.zip -d /Users/Desktop/Desktop/something", capture_output=True).stdout

to

output = run(["unzip", "-P", "password", "/Users/username/Desktop/something.zip", "-d", "/Users/Desktop/Desktop/something"], capture_output=True).stdout

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM