by Devin Yang

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

最简化版本的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, api

Swagger介绍

最好的API是使用Swagger工具创建的, 本文介绍如何用docker来运行swagger-ui及editor,让我们创建出可测试的API文档。 在docker的环境,我们可以很轻松的启动swagger编辑器及使用者接口。

docker,cli

Docker容器格式化显示

我觉的如果要写一些自动化功能,或许能够格式化的输出容器内容还满有用的。以下一些Docker容器格式化显示命令的参考范例

linux

如何建ssh密钥,让自己的电脑可以连到 GCE的instance

最近刚好开始使用Google的GCE,日志一下Goolge官方的说明文档,如何生成密钥给instance使用。 这里的-C comment会用登录使用者的名称,另外-t使用rsa。