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

需要登入才可留言!

类似文章


linux,mac

MacOS或Linux上的密码生成器

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

日志我在MacOS编译siege

Siege是一个http负载测试和基准测试工具。 用来对进程码进行压力测试。 Siege支持基本认证,cookies,HTTP,HTTPS和FTP协议。 它允许使用者,可以用来模拟并发的连线等访问网页伺服器。

linux, python, colab

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

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