Re: Executing a DOS program from within Python

2006-03-16 Thread Gary Herron
Randy Kreuziger wrote:

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


  

There has been numerous ways to do this in the past (os.system, 
os.spawn, os.exec, and various operations in popen2), with os.system 
being the easiest and perhaps sufficient for your need.

However, if you are running Python 2.4, the I'd suggest the subprocess 
module, and in particular its convenience function call.

Gary Herron

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing a DOS program from within Python

2006-03-16 Thread 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!!

-- 
http://mail.python.org/mailman/listinfo/python-list