[Tutor] Hiding/Killing a DOS window (from a previous os.system call)

learner404 learner404 at gmail.com
Mon Mar 5 19:16:10 CET 2007


Thanks a lot Alan !  both solutions work like a charm :)


On 3/5/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
>
> "learner404" <learner404 at gmail.com> wrote
>
> > I'm launching an external app through an os.system() or os.popen()
> > but I
> > don't want the resulting DOS window to hang-on there forever
>
> Try using os.spawnl() instead:
>
> >>> pid = os.spawnl(os.P_NOWAIT,r'C:\Windows\System32\notepad.exe')
> >>> print pid
> 2834
>
> The P_NOWAIT makes it return immediately, and no DOS box
> is created.
>
> Note that the spawn family of processes are deprecated and the
> subprocess module provides equivalent functionality.
>
> Using subprocess it looks like:
>
> >>> pid = Popen([r'C:\Windows\System32\notepad.exe', ""]).pid
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070305/f796df14/attachment.html 


More information about the Tutor mailing list