passing command line arguments to executable

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Apr 4 18:23:07 EDT 2010


On 4 abr, 06:17, Francesco Bochicchio <bieff... at gmail.com> wrote:
> On 3 Apr, 19:20, mcanjo <mca... at gmail.com> wrote:
> > On Apr 3, 11:15 am, Patrick Maupin <pmau... at gmail.com> wrote:
> > > On Apr 3, 11:09 am, mcanjo <mca... at gmail.com> wrote:
>
> > > > I have an executable (I don't have access to the source code) that
> > > > processes some data. I double click on the icon and a Command prompt
> > > > window pops up. The program asks me for the input file, I hit enter,
> > > > and then it asks me for and output filename, I hit enter a second time
 
^^^^^^^^^^^^^^^^^^^^^^^^^
> > > > and it goes off and does its thing and when it is finished ...
>
> > > You need to look at the subprocess module, and use pipes.
>
> > I tried doing the following code:
>
> > from subprocess import Popen
> > from subprocess import PIPE, STDOUT
> > exefile = Popen('pmm.exe', stdout = PIPE, stdin = PIPE, stderr =
> > STDOUT)
> > exefile.communicate('MarchScreen.pmm\nMarchScreen.out')[0]
>
> > and the Command Prompt opened and closed, no exceptions were generated
> > but the program didn't run. Am I doing something wrong?
>
> I would try a couple of things (never done what you are trying to do,
> so my suggestions may be useless ):
> 1. use shell=True as parameter of Popen
> 2. capture the output of communicate method, which returns whatever
> the process emits on standard output and standard error: there could
> be some message that give you hints about the solution.

To mcanjo: note that you didn't provide the second '\n'

Also, are you sure the program does not accept command line arguments?
Many do, and switch to interactive mode when no argument is provided.
I'd try with -h /h --help /help -? /?

--
Gabriel Genellina



More information about the Python-list mailing list