Running a DOS exe file from python

L

lblr33

I would like to execute a windows program from python and wait for it
to finish before returning to the python script.

The script I want to run has a set number of arguments.

The following does work fine:
os.system(r"c:\tmp\myprog.exe arg1 arg2 arg3")

The problem I have is that the path to myprog.exe and the arguments are
variable so I need to pass them in as arguments to myprog.exe.

Thanks
 
R

Rinzwind

Hello,

Something like this:
progname = 'c:\tmp\myprog.exe arg1 '+'-- help'
os.system(r'progname)

should work too.
So you should be able to change progname to any location you need to
start it and all the args to whatever is needed.
 
P

Peter Hansen

Rinzwind said:
Something like this:
progname = 'c:\tmp\myprog.exe arg1 '+'-- help'
os.system(r'progname)

Well, other than the ways in which it wouldn't work:

1. "arg1" doesn't get substituted with anything, if that's what you
meant, but rather is inserted as the literal string "arg1". If you
meant that just as an example of some other argument that would be
hardcoded, then it's unclear why you have the + in there since you could
just have written the whole thing as a single string.

2. You need the 'r' meaning raw string *on the string literal*, in the
first line, not in the second line. In your code, the string bound to
the name "progname" contains an ASCII TAB character in the third byte,
after the "c" and the ":", which isn't likely what you wanted.

3. In the second line you have an unterminated string...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top