passing command line arguments to executable
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 running the Command Prompt goes away and I have my new output file in the same directory as my executable and input file. I would like to be able to batch process a group of files. I thought about using "os.spawnv()" in a loop and at each iteration of the loop passing in the file in and out names but that didn't work. Does anyone have any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: passing command line arguments to executable
On Apr 3, 11:15 am, Patrick Maupin wrote: > On Apr 3, 11:09 am, mcanjo 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 running the > > Command Prompt goes away and I have my new output file in the same > > directory as my executable and input file. I would like to be able to > > batch process a group of files. I thought about using "os.spawnv()" in > > a loop and at each iteration of the loop passing in the file in and > > out names but that didn't work. Does anyone have any ideas? > > You need to look at the subprocess module, and use pipes. > > Regards, > Pat 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? -- http://mail.python.org/mailman/listinfo/python-list
Re: passing command line arguments to executable
On Apr 4, 6:32 am, Simon Brunning wrote: > On 3 April 2010 18:20, mcanjo wrote: > > > 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? > > Have you tried running pmm.exe from the command line? What does that > look like? Does it matter what the current working directory is at the > time? > > -- > Cheers, > Simon B. When I run the program from the command line it looks as follows: Enter the Input filename (enter in filename here) Enter the Output filename (enter in filename here) If an absolute path is not specified then the output file is located in the current working directory of the executable. The absolute path for the output and input files may be specified also. Chris -- http://mail.python.org/mailman/listinfo/python-list