[Tutor] subprocess and launching an editor

Brian van den Broek broek at cc.umanitoba.ca
Fri Jun 22 16:57:02 CEST 2007

Hi all,

I want to have a script launch an editor open to a particular file and 
wait until that editor has closed before continuing. The aim is to 
allow the user to make edits to the file, have to script know that the 
edits are completed, and then make use of the newly saved file contents.

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)

works just fine *provided* that no instance of gedit is running when I 
invoke .call. However, if there is a gedit window up and running 
(there usually is on my system ;-), the .call immediately returns exit 
status 0:

 >>> subprocess.Popen("ps -e|grep gedit", shell=True)
<subprocess.Popen object at 0xb7d06b4c>
 >>> 26066 pts/2    00:00:01 gedit

 >>> subprocess.call("gedit somefilename", shell=True)
 >>> # The exit code is produced instantaneously

Interestingly, it works just fine if I use emacs in place of gedit, 
irrespective of whether emacs was running before the subprocess.call 
invocation or not. Is there any way to get it to work with gedit as it 
is with emacs?

I am largely ignorant of the family of modules which subprocess was 
designed to replace, and also of the details of processes on linux. 
(In particular, I've no clue why gedit and emacs behave differently in 
this respect.)

Thanks and best,

Brian vdB

More information about the Tutor mailing list