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

需要登入才可留言!

类似文章


linux

如何检查apache加载并激活了那些modules?

如何检查apache加载并激活了那些modules?

laravel docker

关於D-Laravel的项目模式

如果您是新使用者,建议您改用我的最新环境phpenv。https://github.com/DevinY/phpenv

ssh,security,config

关於SSH_USER_AUTH

在OpenSSH 7.6后,可以在sshd_config的设置档中添加ExposeAuhtInfo yes的参数,重启sshd,然后再登录,就会有环境变量$SSH_USER_AUTH这能功写暂存档在tmp中,文件内含登录公钥