by Devin Yang

建立于: 2年前 ( 更新: 2年前 )

我用Python运行系统命令的范本

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE, STDOUT

command='uname -a'.split()

proc=Popen(command ,bufsize=0, stdout=PIPE,stderr=PIPE, universal_newlines=True);
output, error = proc.communicate()
exit_code=proc.poll()

if (exit_code==0):
  print(output)
else:
  print(error)

Tags: python

Devin Yang

文章内容无法一一说明,如果您有什么不了解处,欢印提问哦:)

No Comment

Post your comment

需要登入才可留言!

类似文章


linux, python, colab

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

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

python

python fastapi速查笔记

简单日志运行fastapi的安装步骤

python

简单测试python-thread功能及参数

日志,如何使用thread运行功能