- Pipe-lining two python programs
- import subprocess
- gen = subprocess.Popen(['python', 'first.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- start = subprocess.Popen(['python','second.py'], stdin=gen.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- start.communicate()
- try:
- while(1):
- print gen()
- time.sleep(1)
- except KeyboardInterrupt:
- sys.exit(1)