[Tutor] Executing dos .bat file with Python script

David Rock david at graniteweb.com
Sun Jul 25 04:17:55 CEST 2004


* Bernard Lebel <python at bernardlebel.com> [2004-07-24 21:54]:
> (sorry Alan if you have received this privately, I'm not used to the need to
> use reply-all to send back to the list)
> 
> 
> Thanks Alan.
> 
> However.... it doesn't seem to work as expected?
> My bat file starts a dos command prompt within the Softimage|XSI
> environment. But when executing the command, well, a command prompt pops but
> closes immediately!
> 
> Python code:
> oFile = file( 'C:\\Python23\\Lib\\experimentation\\xsi.bat', 'r' )
> os.system( str( oFile.read() ) )

your python code should be:
os.system( 'C:\\Python23\\Lib\\experimentation\\xsi.bat' )
That spawns a shell and runs the given command within it.

Also, look at the commands module if you need to get status or output,
too.
http://docs.python.org/lib/module-commands.html

-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20040724/4adb26bc/attachment.pgp


More information about the Tutor mailing list