六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 49|回复: 0

Python执行外部程序

[复制链接]

升级  54.33%

111

主题

111

主题

111

主题

举人

Rank: 3Rank: 3

积分
363
 楼主| 发表于 2013-1-15 02:36:11 | 显示全部楼层 |阅读模式
# -*- coding:UTF-8 -*- import osimport subprocessclass ExeMgr(object):    '''Python管理应用程序    '''    def __init__(self,appPath):        '''        appPath:要启动的应用程序的路径        pid:启动的进程id        '''        self.appPath = appPath        self.pid = None            def start(self):        '''            启动应用程序        '''        #判断应用程序路径是否存在        if(os.path.exists(self.appPath)):            p = subprocess.Popen(self.appPath)            self.pid = p.pid            if self.pid is None:                return False            return True        else:            print '应用程序路径'+self.appPath+'不存在'                        if __name__ == '__main__':        exeMgr = ExeMgr(r"C:\Program Files\Tencent\QQ\Bin\QQ.exe")    exeMgr.start()    print '程序已成功启动'
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表