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

需要登入才可留言!

类似文章


Raspberry

Raspberry播放midi档

Raspberry播放midi音乐

dlaravel

如何设置外网IP给D-Laravel上的Project?

这个影片介绍了在D-Laravel环境上,我们如何指定Public Ip(公有IP)给特定的Project的使用。 不论是外部Production环境的设置或是内网自己项目Demo时,都可参考此影片的设置方式哦 。 在影片中虽然我采用了PPPoE拨接的外网IP进行说明,但是我们改变一下也可以用自己电脑上的区网IP。 这样就可以让同事连到我们的D-Laravel的Project了。

linux

如何安装monitor工具htop到CentOS上

Htop是一个基於Linux的免费(GPL)基於ncurses的进程monitor工具。 他类似於top,但允许您垂直和水平滚动,所以您可以看到运行在系统完整的命令行, 以及可将它们视为进程树,选择多个进程并进行操作。