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

需要登入才可留言!

类似文章


fpm

在container内重启php-fpm

在container内重启php-fpm

laravel

Laravel维护模式下的随机密码

本文所提到的功能需为Laravel 8及之后的版本才可以使用假如我们有一些有外部IP的Laravel外部的测试网站,但是只想给自己访问。我是这么做的提供参考

docker

关於Docker的Logging Driver

Docker内建相当多的日志机制,帮我们取得在container内运行的服务信息。 这些机制(mechanisms)我们通常称为logging drivers.