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

需要登入才可留言!

类似文章


docker,container,laravel

在Nas上手动更新D-Laravel的使用者id全日志

本文全日志,绍我如何更新我家Nas上的fpm image的uid。 本文章中,您应该会学会查询容器id及commit容器等相关概念。

cli,linux,macos

如何用find删除创建时间为准的旧文件

这功能很好用,但要很小心,先看再删,弄错目录会死很惨 

terminal,shortcuts,bash

终端机热键攻略

本文介绍及整理一些终端机的热键,来看看有那些你不知道的吧?快来试试。