calling .exe inside a .py?

greg at perceval.be.bbs greg at perceval.be.bbs
Fri Jul 14 06:20:04 EDT 2000


In reply to the message of shindich at my-deja.com sent on Jul 13 (see below) :

> Try this:
>
> import os
> os.execl ('foo.exe')

execl is  kind of alias for execv. So using this solution, be aware of the
following:

execv (path, args)
Execute the executable path with argument list args, replacing the
current process (i.e., the Python interpreter). The argument list may be a
tuple or list of strings. Availability: Unix, Windows.

This mean tha if you have the following code in a file:

	import os
	os.execv("/bin/ls",("ls","/"))
	print "Done!"

Last line will never be executed because the python process is replaced by
the /bin/ls command. To avoid this, Unix allows you to use the fork system
call :
	import os
	i= os.fork()
	if i != 0:
		os.waitpid(i,0) # wait for the child to complete.
		print done!
	else:	#  child process
		os.execv("/bin/ls",("ls","/"))
	
An other and easier solution which also works under Windows :

	import os
	os.system("foo.exe")
	print 'Done!'


Sincerly yours

--
Life is not fair
But the root password helps
--

Gregoire Welraeds
greg at perceval.be
Perceval Development team
-------------------------------------------------------------------------------
Perceval Technologies sa/nv	Tel: +32-2-6409194
Rue Tenbosch, 9			Fax: +32-2-6403154
B-1000 Brussels			general information:   info at perceval.net
BELGIUM				technical information: helpdesk at perceval.net
URL: http://www.perceval.be/
-------------------------------------------------------------------------------

On Thu, 13 Jul 2000 shindich at my-deja.com wrote:

> Date: Thu, 13 Jul 2000 19:51:21 GMT
> From: shindich at my-deja.com
> To: python-list at python.org
> Newsgroups: comp.lang.python
> Subject: Re: calling .exe inside a .py?
>
> In article <8kl527$tke$1 at nnrp1.deja.com>,
>   level2junkie at my-deja.com wrote:
> > Does anyone know how to call an .exe file from inside a .py file?
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
> Try this:
>
> import os
> os.execl ('foo.exe')
>
> For more info read http://www.python.org/doc/current/lib/os-process.html
>
> Regards,
>
> Alex Shindich
> http://www.shindich.com/
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> --
> http://www.python.org/mailman/listinfo/python-list
>
>



More information about the Python-list mailing list