RE: Python toy process launcher

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

 

 

Nod that is the problem with python for windows and Linux it acts different
in a few strange ways.  If you don't know about the differences they can
bite you.

 

Ken

 

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of R Dinger
Sent: Friday, December 11, 2009 9:53 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Python toy process launcher

 

Hi Ken,

 

Strange, I did this in version 2.6 on Win XP.

 

I originally had the first arg of Popen as:

['python', 'test.py']

 

But changed it to a string thinking that would be more clear for most folks.
Maybe the named arg:

shell=True

 

should be set for a string arg, but it works fine on my machine as is.

 

Richard

----- Original Message ----- 

From: Ken Perry <mailto:whistler@xxxxxxxxxxxxx>  

To: programmingblind@xxxxxxxxxxxxx 

Sent: Thursday, December 10, 2009 9:28 PM

Subject: RE: Python toy process launcher

 

 

 

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: