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

需要登入才可留言!

类似文章


dlaravel

如何启动D-Laravel上的supervisor

由於queue workers是一个长期运行的进程,所以我们会需要一个进程管理员supervisor来监控Linux系统上的process是否持续运作,例如:当queue:work运作失败时,可以自动重启queue:work process。很幸运的D-Laravel已内建supervisor罗,所以不需要再自行安装即可使用。 本文简单的介绍,我们如何来启动container内的supervisor。

macos

macOS上的say命令语音清单

如何在macOS上的终端机说国语,或是广东话呢? 点进来看看

Ubuntu

Ubuntu上的ps命令的包

日志如果系统未安装ps时,如何手动安装