RE: Python toy process launcher

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 11 Dec 2009 00:28:54 -0500

 

 

By the way your code fails to execute with python2.6 in ubuntu it says it
can't find test.py even though it is there.  It's actually pretty strange.
I even put '.' In the path and I tried adding the full path to test.py.  I
have not run into this problem before with python.

 

Ken

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of R Dinger
Sent: Wednesday, December 09, 2009 7:27 PM
To: programming
Subject: Python toy process launcher

 

The code follows:

---------

# runTest.py provide interface and run test.py engine

 

import subprocess

 

# launch the engine child process:
engine = subprocess.Popen("python test.py",
    universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

 

# user interaction main loop:
while(True):
  # get a move from user:
  playerMove = raw_input("Enter a move ")

 

  # exit if done:
  if playerMove == 'exit':
    break

 

  # send player move over to engine:
  engine.stdin.write('%s\n' % playerMove)

 

  # get reply from engine:
  engineMove = engine.stdout.readline().strip('\n')

 

  # show response from engine:
  print "Engine response:>%s<" % engineMove
  # end of while loop

 

# termination processing:
if engine.poll() is None:
  # kill the subprocess:
  engine.kill()

 


 

Other related posts: