1.コールPythonスクリプトパイソン
#!/usr/local/bin/python3.7
import time
import os
count = 0
str = ('python b.py')
result1 = os.system(str)
print(result1)
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')
別のPythonスクリプトのb.py次のように:
#!/usr/local/bin/python3.7
print('hello world')
結果:
[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
)(シェル方式os.systemを呼び出す2.python
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
#!/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')
次のようにシェルスクリプトは次のとおりです。
#!/bin/sh
echo "hello world"
結果:
[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
)(シェル方式os.popenを呼び出す3.python
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
#!/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')
結果:
[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
os.system.popen()このメソッドは、導管を開き、その結果、接続パイプ、同じファイルオブジェクトを開き(操作方法)のファイルオブジェクトであり、結果はファイルオブジェクトから読み取ることができる返します。成功した場合、それが実行に失敗した場合、エラーメッセージがstdoutに出力され、空の文字列を返し、ステータスコードを返しません。ここでは、公式にはまた、サブプロセスモジュールは、より強力なsubprocess.Popen()メソッドを達成したと述べました。