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

需要登入才可留言!

类似文章


python

用python运行系统命令

我如何用Pyhton运行系统命令,这里有个简单的范例

linux,termux

如何在android手机背景播放mp4或webm

我有些Youtube下载下来的音档想要在背景播放,我知道如何做啦?

config,vim

Vim在Ubuntu上的中文环境

如果Vim设置是中文环境,但Ubuntu安装时未设置为zh_TW.UTF-8,那要如何安装这个环境?