calling ksh script from python

Donn Cave donn at u.washington.edu
Thu Jun 2 12:04:58 EDT 2005


In article <1117722690.144752.82250 at g14g2000cwa.googlegroups.com>,
 ronan_boisard at yahoo.com wrote:
...
> I call it from python like that:
> -- begin ---
> import commands
> commands.getstatusoutput('. toto.env')
> -- end ---
> 
> but it always return an error saying:
> sh: TOTO_ENV=/home/home: is not an identifier
> 
> doesn anyone know why ?

...


> and what about this sh primpt in the error message, can't I use ksh
> script ?

Yes and no.  You can expect system(), popen() et al. to
invoke the standard UNIX shell, "sh", so you must supply
an expression that will be correctly executed by that shell.
That expression can execute a program written in another
language - for example, 'ksh toto.env' or just './toto.env'
if you have made it executable and it starts with #!/bin/ksh.
That's really the best way to invoke a script.

Meanwhile, it might be worthwhile to reconsider the use
of ksh here, if you have any choice in the matter.  Ksh
is fine for interactive use, but has some unfortunate
flaws as a programming shell, and due to proprietary issues
one commonly encounters an alternative implementation that's
even worse.  On most modern platforms, sh will have a pretty
good programming feature set, and will be more reliable
(especially if it isn't just ksh by another name.)

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list