Starting terminal applications from within python

sleepylight sleepylight at gmail.com
Thu Feb 2 12:01:11 EST 2006


Hi

I'm staring to learn python for some systems administration projects
and so far this looks like a really great alternative to using shell
for everything.  The python docs on the web site are really great, but
I could use come clarification on passing arguments using the
os.spawnlp() function.

For example, if I run  "xterm -e /opt/itt/ncbr/bin/linux/bar" I get an
xterm executing my nice little test program.  However, if I try to run
that same commad in python it doesn't work so well.

>>> os.spawnlp(os.P_NOWAIT, "/usr/bin/xterm", "/usr/bin/xterm", "-e /opt/itt/ncbr/bin/linux/bar")
4940
>>> /usr/bin/xterm:  bad command line option "-e /opt/itt/ncbr/bin/linux/bar"

usage:  /usr/bin/xterm [-/+132] [-C] [-Sccn] [-T string] [-/+ah]
[-/+ai]
    [-/+aw] [-b number] [-/+bc] [-bcf milliseconds] [-bcn milliseconds]
    [-bd color] [-/+bdc] [-bg color] [-bw number] [-/+cb] [-cc
classrange]
    [-/+cjk_width] [-class string] [-/+cm] [-/+cn] [-cr color] [-/+cu]
[-/+dc]
    [-display displayname] [-e command args ...] [-fa pattern] [-fb
fontname]
    [-/+fbb] [-/+fbx] [-fd pattern] [-fg color] [-fi fontname] [-fn
fontname]
    [-fs size] [-fw fontname] [-fwb fontname] [-fx fontname] [%geom]
[#geom]
    [-geometry geom] [-hc color] [-help] [-/+hold] [-iconic] [-/+ie]
[-/+im]
    [-into windowId] [-/+j] [-/+k8] [-kt keyboardtype] [-/+l] [-/+lc]
    [-lcc path] [-leftbar] [-lf filename] [-/+ls] [-/+mb] [-mc
milliseconds]
    [-/+mesg] [-/+mk_width] [-ms color] [-n string] [-name string] [-nb
number]
    [-/+nul] [-/+pc] [-/+pob] [-rightbar] [-/+rv] [-/+rvc] [-/+rw]
[-/+s]
    [-/+samename] [-/+sb] [-/+sf] [-/+si] [-/+sk] [-sl number] [-/+sm]
[-/+sp]
    [-/+t] [-ti termid] [-title string] [-tm string] [-tn name] [-/+u8]
    [-/+ulc] [-/+ulit] [-/+ut] [-/+vb] [-version] [-/+wc] [-/+wf]
    [-xrm resourcestring] [-ziconbeep percent]

Type /usr/bin/xterm -help for a full description.


I thought maybe I needed a space before the '-e' for some reason, but
that didn't really help:
>>> os.spawnlp(os.P_NOWAIT, "/usr/bin/xterm", "/usr/bin/xterm", " -e /opt/itt/ncbr/bin/linux/bar")
4943
>>> No absolute path found for shell:  -e /opt/itt/ncbr/bin/linux/bar

So, I guess that I'm not reading how to set up the arguments to
spawnlp() correctly.  Does anyone else have some experience with this?




More information about the Python-list mailing list