【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 ...
随机推荐
- 【BZOJ1968】【AHoi2005】COMMON约数研究
Description Input 只有一行一个整数 N(0 < N < 1000000). Output 只有一行输出,为整数M,即f(1)到f(N)的累加和. Sample Input ...
- ObjectContext,DataContext和DBContext 分别获取linq 的sql方法
ObjectContext 先定义一个扩展方法: public static string ToTraceString<T>(this IQueryable<T> t) { s ...
- GO语言练习:网络编程 ICMP 示例
1.代码 2.编译及运行 1.Go语言网络编程:ICMP示例代码 icmptest.go package main import ( "fmt" "net" & ...
- CSS去除firefox点击链接时的虚线边框
a { outline: none; } 或者缩小范围: a:focus { outline: none; }
- Oracle-表格的建立
表格的建立,在table分列鼠标右键: 在名称写上此表格的名称,最好用英文,中文容易报错.表空间默认为user,也可以自己选择. 数据类型,一个汉字占用3个字节,最好多定义一些字节,防止出错. 可为空 ...
- getElementsByClassName的兼容性
/*----------------------------index.html------------------------------------*/ <!DOCTYPE html> ...
- Jfinal中手动提交/回滚 事物
在Jfinal中有个Tx类为事物声明类 在方法或controller上面加@Before({Tx.class})即可,可是这样并不能满足有的业务场景 下面是今天写的手动提交的事物处理方法,希望对大家有 ...
- JAVA创建并写入内容到xlsx文件
首先需要在web项目中导入jxl.jar 包 //action中代码 public String downloadReport(){ String path = System.getPr ...
- js变量
由于undefined和null两个值的比较是相等的,所以,未初始化的变量和赋值为null的变量会相等.这时,可以采用typeof变量的类型进行比较.但,建议还是养成编码的规范,不要忘记初始化变量. ...
- 打开FileGeoDatabase中要素类
private IFeatureClass OpenFileGdbFtCls(string fn) { IFeatureClass pftcls = null; IWorkspaceFactory w ...