python调用外部命令获得执行结果,python外部命令,要在python中调用外
python调用外部命令获得执行结果,python外部命令,要在python中调用外
要在python中调用外部命令必须引入subprocess模块。
如下方法,执行ls命令并获得返回值
import subprocessp = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)for line in p.stdout.readlines(): print line,retval = p.wait()
如果不需要返回值,只需要简单调用,可以简单一些:
subprocess.call(['ping', 'localhost'])
相关内容
- python正则表达式re模块使用总结,python正则表达式,一、
- Pythonic的Redis库 OOREDIS 介绍,pythonicredis,用Redis的朋友们
- python使用pgsql连接postgresql,pgsqlpostgresql,决定使用pytho
- python读写excel例子,python读写excel,你知道吗?python也
- python中清除html标签,pythonhtml标签,如下代码实现清除
- python手动释放 内存的问题, python explicitly free memory.,
- python使用unittest进行单元测试,pythonunittest,simptest.py#
- python时间和时间戳之间的相互转换,python时间相互转换
- python filter使用示例,pythonfilter示例,列表用得比较多,
- python使用ConfigParser库读取配置文件,pythonconfigparser,温习
评论关闭