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

需要登入才可留言!

類似的文章


dlaravel

如何透過getssl自動檢測及更新let's encrypt發出的憑證

let's encrypt提供免費的憑證真的很棒,不過,三個月要更新一次憑證是不是有點麻煩, 本文介紹,如何透過getssl,產生多域名的SAN憑證設定,放入排程自動進行憑證更新。 非常簡單哦,六個步驟即可搞定。

vim

關於vimdiff

我的vimdiff小抄

git

參除git遠端或本地端的tag

如何參除git遠端或本地端的Tag.