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

需要登入才可留言!

类似文章


laravel

Laravel思绪整理,从Model到DatabaseSeeder.

本文将一步一步介绍相关的命令用例: Model=>Factory=>Seeder=>DatabaseSeeder 一步一脚印,让我们就从Model开始检视所有流程到DatabaseSeeder。

linux

haproxy 1.8.9编译日志

日志在Ubuntu下编译haproxy 1.8.9过程。

linux

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

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