您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關(guān)怎樣調(diào)用python中shell腳本,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
1. python調(diào)用shell方法os.system()
#!/usr/local/bin/python3.7 import time import os count = 0 n = os.system('sh b.sh') while True: count = count + 1 if count == 8: print('this count is:',count) break else: time.sleep(1) print('this count is:',count) print('Good Bye')
shell腳本如下:
#!/bin/sh echo "hello world"
運行結(jié)果:
[python@master2 while]$ python a.py hello world this count is: 1 this count is: 2 this count is: 3 this count is: 4 this count is: 5 this count is: 6 this count is: 7 this count is: 8 Good Bye
2. python調(diào)用shell方法os.popen()
#!/usr/local/bin/python3.7 import time import os count = 0 n = os.system('sh b.sh') while True: count = count + 1 if count == 8: print('this count is:',count) break else: time.sleep(1) print('this count is:',count) print('Good Bye')
運行結(jié)果:
[python@master2 while]$ python a.py <os._wrap_close object at 0x7f7f89377940> ['hello world\n'] this count is: 1 this count is: 2 this count is: 3 this count is: 4 this count is: 5 this count is: 6 this count is: 7 this count is: 8 Good Bye
關(guān)于怎樣調(diào)用python中shell腳本就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。