Executing a DOS program from within Python

R

Randy Kreuziger

This is probably a newbie question but I need a kick start to get going.

I need to run a DOS (sdetable) program from within a Python program. I'll use command line switches so I will not need to interact with the program however it would be nice if I could capture its exit code.

Thanks


Randy Kreuziger
(360) 902-2495 Voice
(360) 902-2940 Fax
ArcSDE Administrator
Wash Dept of Fish and Wildlife
 
I

iapain

Use os.system and if you wanna get rid of console window use subprocess
as gary said, you could have better options like killing proc if it
hang/stuck using win32api (if you are using windows) else process
timeout.

ret = os.system('sample.exe') # ret will have return code and os.system
execute sample.exe

#using subprocess

import subprocess
process = subprocess.Popen('sample.exe', stdout=subprocess.PIPE)
#you can print error/output using stderr/stdout pipe

Both are easy to implement!
Thanks!!
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top