Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- import subprocess
- command = [sys.executable, 'tok2.py']
- proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- i=0
- while proc.poll() is None:
- if i > 5:
- #Send 'exit' after 5th iteration
- proc.stdin.write(b'exit')
- print('tok1: ' + str(i))
- time.sleep(0.5)
- i=i+1
- import sys
- import time
- ii=0
- my_input =''
- while True:
- my_input = sys.stdin.read()
- if my_input == b'exit':
- print('tok2: exiting')
- sys.stdout.flush()
- break
- print('tok2: ' + str(ii))
- sys.stdout.flush()
- ii=ii+1
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement