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

需要登入才可留言!

类似文章


fastapi,phpenv,docker

我如何用phpenv创建fastapi运行环境

虽然phpenv主要用於运行PHP Laravel的环境,但不代表他不能跑其他语言或其他容器。本文介绍,我如何让phpenv跑python的fastapi环境,当然这只是一个概念,目前为止,我已经让PHP api跑HAProxy了,并且自动申请及更新免费证书,现在就让他来跑Python的fastapi吧。phpenv没有什么限制,限制的是您的想像力😆

docker

用bash更新docker-compse版本

安装最新版本的docker-compose