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

需要登入才可留言!

类似文章


docker

Docker image的封存及取回

如何封存docker的image成为tar档,并且载回docker image。 我们可以用docker save及docker load进行。

jQuery

Uncaught TypeError: Cannot read property 'msie' of undefined 错误信息(jQuery)

Uncaught TypeError: Cannot read property 'msie' of undefined 出现这个信息的原因

git

透过git命令显示自己的版控,例如7天内?

如何透过git命令显示自己的版控?这些命令仅供参考,至少应该改一下作者名称哦。--author的参数,也可以是信箱