[PyKDE] Launching an App from PyQt

Jens Nie Jens.Nie at uos.de
Thu Jan 16 20:32:00 GMT 2003


Am Donnerstag, 16. Januar 2003 18:59 schrieb Jonathan Gardner:
> I'm feeling really stupid about now.
>
> I think I remember seeing a thread about someone trying to launch an
> application from an application. I am running into that problem right now.
>
> Coming from a perl world, I never gave a second thought about how to do
> this. Now I am befuddled by the variety of options: system, popen, spawn,
> and so much more.
>
> I've tried a few of the above with varying amounts of success. I think the
> best was something like:
>
> os.system("python theapp.py &")
>
> although I know that this isn't quite right. Anyone have a favorite idiom
> they like to use from PyQt?

Well. There are several ways to do this in python. I don't think this is PyQt 
specific..

The quick and dirty way will be:

import commands

status, output = command.getstatusoutput('Application')
if status:
		# some error handling of course

this will launch your Application in a subshell. It is only available in Unix 
and alikes


the more elegant and portable way is to use the exec* or spawn* methods. This 
is the direct way.

os.spawnl(os.P_NOWAIT, 'pathtoyourApplication', 'pathtoyourApplication', 
'/dev/null')

using os.P_NOWAIT you can prevent your calling application to wait for the 
called Application to finish. use os.P_WAIT to wait for it. notice the 
/dev/null as the last parameter. As in C the function call has to be 
terminated. I think this is the tricky thing using these methods. The exec* 
methods work just the same way, and besides the /dev/null statement just as 
in C.

to process output you can use the os.popen* calls. They return filehandles to 
your application, so you can feed it and read from it.

Hope that helped

Jens

-- 
				Dipl.-Phys. Jens Nie
	Research & Development/Physics, Rosen Inspection, Lingen
JNie at RosenInspection.net, http://godot.physik.uni-osnabrueck.de/~jnie




More information about the PyQt mailing list