by Devin Yang

建立于: 7年前 ( 更新: 7年前 )

最简化版本的Python系统命令运行范本

#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE, STDOUT
#运行的命令
command='ls -l'.split()
proc=Popen(command , stdout=PIPE,stderr=PIPE, universal_newlines=True);
output, error = proc.communicate()

#显示运行结果
if(proc.poll()==0):
     print(output)
else:
     print("{} Error\n".format(error))


 

Tags:

Devin Yang

文章内容无法一一说明,如果您有什么不了解处,欢印提问哦:)

No Comment

Post your comment

需要登入才可留言!

类似文章


ffmpeg

ffmpeg的批转档技巧webm转mp3

这篇文章介绍我如何在一个目录中进行多文件格式转换。 当您学会了肯定可以变出新的花样来。

爬蟲

selenium安装

Python language bindings for Selenium WebDriver.

docker

关於Docker的Logging Driver

Docker内建相当多的日志机制,帮我们取得在container内运行的服务信息。 这些机制(mechanisms)我们通常称为logging drivers.