Created
October 25, 2018 03:14
-
-
Save taojy123/6ffeea3eeef53bce5df22fa3c97203db to your computer and use it in GitHub Desktop.
python 执行命令行 获取结果
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============ python2 ==================== | |
import commands | |
commands.getoutput("ls") | |
commands.getstatus("ls") | |
status, output = commands.getstatusoutput("ls") | |
# ============ python3 ==================== | |
from subprocess import Popen, PIPE | |
p = Popen("ls", shell=True, stdout=PIPE, stderr=PIPE) | |
p.wait() | |
p.stdout.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment