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

需要登入才可留言!

類似的文章


python

簡單測試python-thread功能及參數

記錄,如何使用thread執行功能

linux, python, colab

如何從我們的Server透過ssh連線到colab?

介紹我寫的一支bash,用來透過ssh連線到colab vm內。 一行指令,搞定colab OpenSSH Server。

python

python fastapi速查筆記

簡單記錄執行fastapi的安裝步驟