python system subprocess win32

kyosohma at gmail.com kyosohma at gmail.com
Tue Aug 7 11:21:31 EDT 2007


On Aug 7, 9:48 am, "mclaugb" <mcla... at nospm.yahoo.com> wrote:
> Hello ALl,
> I have a compiled program "conv.exe" that works as follows:>>conv.exe
>
> -----------------------------
> Please selection from the following options.  press "h" for help, "p" for
> print, "r" for readfile.
> Enter your request now:
> ...
> --------------------
> Is there a way to script python using the subprocess method to start this
> program "conv.exe" and then send a "r" to the command line to make it, say,
> readfile.
>
> I have tried the following but the .communicate("r) is not doing anything
>
> import subprocess
> import time
>
> a=subprocess.Popen("c:\\mcml\\conv.exe")
> time.sleep(1)
> (stdout, stderr) = a.communicate("r")
>
> Many thanks,
> Bryan

Use the sys.argv method. In the code that you have compiled, put the
following lines in:

<code>

import sys
default = sys.argv[1]
if default:
   # check which option it is and run it appropriately
else:
   # print your menu here

</code>

Then you should be able to do the subprocess Popen command:

subprocess.Popen("c:\\mcml\\conv.exe r")

You may need to turn the shell on...

subprocess.Popen("c:\\mcml\\conv.exe r", shell=True)

Hopefully that gives you some ideas anyway.

Mike




More information about the Python-list mailing list