파이썬 스크립트의 세 가지 다른 방법으로, 당신은 다른 방법을 알고 전화를?

1. 전화 파이썬 스크립트 파이썬

#!/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')

또 다른 파이썬 스크립트 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 ()이 방법은, 도관을 열어 그 결과, 접속 관의 파일 오브젝트, 동일한 파일 오브젝트 열기 (동작시키는 방법)이다 결과 파일 오브젝트로부터 판독 될 수 리턴한다. 성공적인 경우, 실행이 실패한 경우, 오류 메시지가 표준 출력으로 출력하고, 빈 문자열을 반환 상태 코드를 반환하지 않습니다. 다음의 공식은 하위 프로세스 모듈이 더 강력한 subprocess.Popen () 메소드를 달성했다.

추천

출처blog.51cto.com/14246112/2464512