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的更多相关文章

  1. 【Python②】python之首秀

       第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...

  2. 【Python】 零碎知识积累 II

    [Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...

  3. 【python】列出http://www.cnblogs.com/xiandedanteng中所有博文的标题

    代码: # 列出http://www.cnblogs.com/xiandedanteng中所有博文的标题 from bs4 import BeautifulSoup import requests u ...

  4. 【python】多进程锁multiprocess.Lock

    [python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报  分类: Python(38)  同步的方法基本与多线程相同. ...

  5. 【python】SQLAlchemy

    来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...

  6. 【python】getopt使用

    来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...

  7. 【Python】如何安装easy_install?

    [Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...

  8. 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】

    1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...

  9. 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】

    1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...

随机推荐

  1. NHibernate one-to-one

    NHibernate里面one-to-one有两种方式:主键关联和唯一外健关联 主键关联: 两个表拥有相同的主键字段,值相同的关联在一起.典型的应用是一个对象的属性太多,将常用的属性跟不常用的附加属性 ...

  2. Eclispe怎么给工作空间下的项目分组

    Eclispe怎么给工作空间下的项目分组 第一步,打开Java Working Set 第二步,添加分组 第三步,选择分组

  3. Nodejs操作redis

    //npm install redis //首先加载node_redis模块 var redis = require('redis'); // 创建redis连接 var client = redis ...

  4. 提交form表单不刷新页面案列

    提交form表单不刷新页面其实很简单的,这里拿上传图片来举列,大家有什么其它的方法也欢迎留言告知与我 <form action="" method="post&qu ...

  5. c#面向对象基础 类、方法、方法重载

    C#是纯粹的面向对象编程语言,它真正体现了“一切皆为对象”的精神.在C#中,即使是最基本的数据类型,如int,double,bool类型,都属于System.Object(Object为所有类型的基类 ...

  6. 关于ASP.NET Web API 客户端的请求报文中添加 Authorization

    当你使用客户端发送请求 Web API 的时候,因为API 有验证,所以你的请求报文中必须有”Authorization“,那么就需要手动添加了! HttpClient client = new Ht ...

  7. Cocos2d-x 开发 v3.2 建立新项目并添加库文件

    一.添加其它类库     3.0以上的设计耦合性强,项目中模块常以库的形式存在,需常添加链接库.在3.0中经常用到CocoStudio 编辑器的资源数据,所以需要添加CocoStudio 库. 1.1 ...

  8. IOS第15天(1,事件处理View的拖拽)

    *******view 一些方法 #import "HMView.h" @implementation HMView // 一个完整的触摸过程 // touchesBegan -& ...

  9. Memcached 笔记与总结(7)增加虚拟节点

    仅仅把 Memcached 服务器集群地址通过一致性哈希转映射在圆环上,可能会出现数据不能均匀地分配给各台 Memcached 服务器. 解决方案是引入虚拟节点,就是把每个映射在圆环上的服务器地址(物 ...

  10. GDC2016 [全境封锁],11个种类5个派系的敌人设计思路

    [汤姆克兰西:全境封锁],11个种类5个派系的敌人设计思路 实现[汤姆克兰西]射击RPG的AI开发   日文链接:http://game.watch.impress.co.jp/docs/news/2 ...