python 执行过终端命令后 怎么获取终端命令的输出
1个回答
展开全部
# -*- coding:utf-8 -*-
__author__ = 'lpe234'
__date__ = '2014-12-29'
from subprocess import Popen, PIPE
resp = Popen('ls -l', stdout=PIPE)
print resp.stdout.read()
输出:
C:\Python27\python.exe D:/11/cs_test/test/ping_ip.py
total 49
-rw-r--r-- 1 LENOVO Administ 345 Nov 2 03:06 Student.py
-rw-r--r-- 1 LENOVO Administ 77312 Nov 2 02:08 ex.xls
-rw-r--r-- 1 LENOVO Administ 353 Nov 20 22:58 for_4.py
-rw-r--r-- 1 LENOVO Administ 2153 Oct 25 19:08 order.py
-rw-r--r-- 1 LENOVO Administ 176 Dec 29 22:43 ping_ip.py
-rw-r--r-- 1 LENOVO Administ 9976 Nov 2 12:49 s.txt
-rw-r--r-- 1 LENOVO Administ 1448 Sep 21 20:33 szsy.py
-rw-r--r-- 1 LENOVO Administ 796 Sep 21 21:19 szsy_2.py
-rw-r--r-- 1 LENOVO Administ 2269 Nov 2 12:49 xls.py
Process finished with exit code 0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询