python 调用shell
来源:互联网 发布:防止蹭网软件 编辑:程序博客网 时间:2024/06/07 22:03
python 在调用系统命令时,如linux shell,可以用os或者subprocess模块,下面介绍subprocess模块
实例:
from subprocess import Popen, PIPEimport datetimeurl_temporary = "/home/adger/Videos/542eea47e4b0e0471d7cff61_v1.orig.mov"video_width = "640"hideo_height = "360"frame_rate = 25video_new_path = "/home/adger/Videos/test1.mp4"result = Popen( "ffmpeg -i '%s' -s %sX%s -vcodec libx264 -profile:v main -preset slow -acodec libfaac -b:a 64k -r %s '%s'" % ( url_temporary, video_width, hideo_height, frame_rate, video_new_path), stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=True,close_fds=True)timeout = 600datetime_start = datetime.datetime.now()while True: datetime_end = datetime.datetime.now() res = result.poll() if res == 0: print result.pid, "end" break elif res is None: if (datetime_end - datetime_start).seconds > timeout: print "timeout",result.pid result.terminate() result.kill() break
result.pid:父进程ID
result.terminate(),杀掉子进程
result.kill(),杀掉父进程
1 0
- python调用shell
- Python 调用shell脚本
- python调用shell
- python调用shell命令
- python中调用shell
- python调用Shell脚本
- Python调用shell命令
- python调用Shell脚本
- python调用shell脚本
- python调用shell命令
- python调用shell
- python调用shell命令
- python调用shell总结
- python调用shell命令
- shell调用python
- python调用shell脚本
- python调用shell命令
- python调用shell命令
- Windows 下 Nginx+IIS 使用
- Android总结篇系列:Android广播机制
- 如何测试一个页面的登录功能
- 如何从零开始开发一款嵌入式产品
- 13、策略模式(strategy)
- python 调用shell
- spring,mybatis事务管理配置与@Transactional注解使用[转]
- 事件处理程序
- 逻辑回归算法——解决分类问题
- [HDU]1556 Color the ball (树状数组--区间更新,单点求值)
- SOAP Webservice和Restful Webservice
- Android上实现圆形选择转盘
- json格式序列化
- xcode升级到8.0版本后拍照功能崩溃问题