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

需要登入才可留言!

类似文章


vim

用Command Line的Vim写Code??

如果你是Vim的初学者,想用Command Line的Vim连到远程主机写Code吗?Ok您来对地方了,请至少考虑看一下本篇。这里提供一个简短的影片介绍如何管理外挂...

linux

移除Ubuntu上旧版本用不到的Linux Kernel

这个页面描述我如何移掉 ubuntu上占空间的旧版本Linux Kernel。

docker,php,cli

MacOS的php不给力,用docker运行laravel installer

非常简单呀,加个「别名」就好了alias laravel='docker run --rm -v ${PWD}:/var/www/html -v ~/.dlaravel/cache:/home/dlaravel/.composer/cache -ti deviny/fpm:8.1.10 /home/dlaravel/.composer/vendor/bin/laravel'