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

需要登入才可留言!

类似文章


gitlab,reset password

重设gitlab密码

用docker建的gitlab太久没用,忘记密码了,如何重设呢。 我们应该能透过下方命令,进入到gitlab容器内...

linux, python, colab

如何从我们的Server透过ssh连线到colab?

介绍我写的一支bash,用来透过ssh连线到colab vm内。 一行命令,搞定colab OpenSSH Server。

dlaravel

D-Laravel的sublime外挂以可由Package Control安装罗。

Mac或Linux的使用者,现在可由Sublime3的package control进行D-Laravel alias的包安装罗。 透过D-Laravel alias,我们可以使用更轻松的方式,运行容器内的artisan及composer命令。 docker的环境,要用composer安装包吗,不需再进入container内,或是设置composer的ce别名,即可在sublime中直接运行。