Vizible’s Blog

Python – How to spawn a process

Posted in Programming, Python by wearetherock on July 31, 2009
1. Process to be spawn
=====================================

# testout.py
button = [ "RIGHT", "LEFT", "UP", "DOWN"]
for i in range(0, len(button)):
    print button[i]

~

2. Main process
=====================================
# testspawn.py
import time
import subprocess as subp
proc = subp.Popen(['python', 'testout.py'], stdin=subp.PIPE, stdout=subp.PIPE, bufsize=0)
while True :
    time.sleep(2)
    line = proc.stdout.readline().strip()
    print line

~

3. Output
=====================================
C:\Data\code\python-win>python testspawn.py
RIGHT
LEFT
UP
DOWN
~
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: