[Tutor] subprocess and launching an editor

Alan Gauld alan.gauld at btinternet.com
Fri Jun 22 18:17:55 CEST 2007


"Brian van den Broek" <broek at cc.umanitoba.ca> wrote

> gedit is the default text editor on my ubuntu feisty system, so in 
> the
> first instance, I've tried to do this with gedit. The 
> subprocess.call:
>
> >>> subprocess.call("gedit somefilename", shell=True)
>

You should probably check the VISUAL and EDITOR environment
settings to find out the users preferred editor. Traditionally VISUAL
outguns EDITOR...

> works just fine *provided* that no instance of gedit is running when 
> I
> invoke .call.

That must be a feature of gedit that it only allows one instance
of gedit to run at a time.

What happens if you try to invoke two instances from an OS prompt?

> Interestingly, it works just fine if I use emacs in place of gedit,

Yep, emacs is happy with multiple instances (or can use emacs
server to ensure multiple calls go to the same client to save 
resources)

> Is there any way to get it to work with gedit as it
> is with emacs?

Change gedit I suspect. At least its open source!

> (In particular, I've no clue why gedit and emacs behave differently 
> in

Almost certainly this is behaviour built into the application.
subprocess.call is pretty much a straight equivalent to os.system
and just returns whatever the app returns...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list