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

需要登入才可留言!

类似文章


linux, cli

如何用find命令,找7天内变动过的文件

如果我们变更过一些文件,如何透过命令行找出来呢?

laravel

在laravel中自定义自己的helper

在Laravel的框架中,包含了相当大量的PHP功能(php functions),称为helper。 https://laravel.com/docs/5.6/helpers 那我们要如何在Laravel中自定义自己的helper呢,其实相当简单呢.. 在composer.json中autoload内的files新建即可。

linux,mac

MacOS或Linux上的密码生成器

有时侯我们需要生成一个随机的密码,但是想破头不知用什么好? 这里提供一个简单的bash让我们轻易的生成一组密码在终端机上。