【Python】 Subprocess module
1. subprocess.check_output()
2.subprocess.call()
3. subprocess.check_call()
the methods 1.2.3 are are wrapper of subprocess.Popen()
- example 1:
Open Visual Studio through python
This way is incorrect.
>>> retcode = subprocess.call('devenv.exe', shell=True)
'devenv.exe' is not recognized as an internal or external command,
operable program or batch file.
Another way:
retcode = subprocess.call("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe",shell=True)
It's done.
Your VS is opened. But the invoke process is blocked. You have to close the process you spawned to get the return code.
- example 2:
try to run iisreset command with python
>>> print subprocess.check_call("iisreset", shell = True)
Attempting stop...
Internet services successfully stopped
Attempting start...
Internet services successfully restarted
0
class Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
What the Popen returns is a child process you want to create.
example 3:
the Popen() process will not be blocked unless we explicit child.wait()
import subprocess
def havewait():
child = subprocess.Popen(['ping','vwijin014'])
child.wait()
print 'parent process' def nowait():
child = subprocess.Popen(['ping','vwijin014'])
#child.wait()
print 'parent process'
Pay attention to the red line order. One is before the ping running.

【Python】 Subprocess module的更多相关文章
- 【Python②】python之首秀
第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...
- 【Python】 零碎知识积累 II
[Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...
- 【python】列出http://www.cnblogs.com/xiandedanteng中所有博文的标题
代码: # 列出http://www.cnblogs.com/xiandedanteng中所有博文的标题 from bs4 import BeautifulSoup import requests u ...
- 【python】多进程锁multiprocess.Lock
[python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报 分类: Python(38) 同步的方法基本与多线程相同. ...
- 【python】SQLAlchemy
来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...
- 【python】getopt使用
来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...
- 【Python】如何安装easy_install?
[Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...
- 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】
1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...
- 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】
1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...
随机推荐
- php关于金额比较引发的问题(转)
做电子商务的时候一般会涉及到金额的比较,按正常的思路来看用><=这些个符号就可以了.可是要是到程序上来搞这个的话就出大事了.现在看下这段代码: $f = 0.07; var_dump($f ...
- 从就业面分析web前端开发工程师就业前景(2011.6)
案例一 公司名称:法国电信北京研发中心 工作地点:北京 联系方式:hao.luan@orange-ftgroup.com 栾先生 岗位名称:web 前端开发工程师 岗位要求: 1. 计算机或相关专业本 ...
- 2015Web前端攻城之路
2015目标成为一名合格的前端攻城狮. 养成计划: 1.html / css 2.js 3.ajax 4.框架 5.项目实战
- mysql体系结构
mysql逻辑架构: 第一层,即最上一层,所包含的服务并不是MySQL所独有的技术.它们都是服务于C/S程序或者是这些程序所需要的:连接处理,身份验证,安全性等等. 第二层值得关注.这是MySQL的核 ...
- app 尺寸
web app 手机桌面logo尺寸大小(三种 ):114 72 57
- java开发常用工具类
package com.rui.util; import java.text.DateFormat; import java.text.DecimalFormat; import java.text. ...
- Python 脚本 监控数据库状态
打算用这个脚本通过zabbix 监控Mariadb的,无奈要等Mariadb完全上线才行,所以先写一个粗略大致功能的版本. #coding:utf-8 #author:shiyiwen #versio ...
- c++ basic 整理2
//拷贝函数 //拷贝构造函数是一种特殊的构造函数,函数的名称必须和类名称一致,它必须的一个参数是本类型的一个引用变量. //不显式指定拷贝函数时,编译器会生成默认拷贝函数. //使用默认拷贝函数 ...
- Unity学习疑问记录之layer问题
在Sprite Render中有个Sorting Layer,这里可以建层,而Inspector窗口中也有个layer,也可以新建层,这2者有什么不一样呢? layer主要通过光线投射来选择性地忽略碰 ...
- Qt常用命令收集
qt的命令很多,用到的时候到网上查,常常不能一下查到.这里记录下一些备用 1 从.ui文件生成头文件: uic xxx.ui > xxx.h 2 moc生成 moc yourfilename.h ...