Getting return value in os.system rsh call

Erik Max Francis max at alcyone.com
Thu Jan 30 21:17:11 EST 2003


Andrew wrote:

> DUH.... Erik, I should have read more closely.....
> 
> ... I need the slash. Then it works. The thing is I've never been
> completely happy with my understanding of Unix quoting.
>
> Can anyone explain why putting the slash in makes a difference?

Yeah, sorry about that.  Shells and quoting can get trickly.  You need
to escape the $ so that $? (which represents the exit code of the last
executed command) doesn't get evaluated on _this_ side of the pipe, but
rather gets evaluated on the remote side along with the ./bad.py
command.

You can even fiddle around with normal variables yourself to see that
(I'll use ssh instead of rsh, but the principle is the same):

max at oxygen:~% x=123
max at oxygen:~% echo $x
123
max at oxygen:~% ssh carbon x=321 \; echo $x
123
max at oxygen:~% ssh carbon x=321 \; echo \$x
321

Another way to avoid all these problems is to use single quotes (which
do not expand variables):

max at oxygen:~% ssh carbon 'x=321; echo $x'
321

> Also, how do I get rid of the stty error messages?

That's rsh doing something weird; I haven't used rsh in years, so I
can't really say what it's up to.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ A man cannot be comfortable without his own approval.
\__/ Mark Twain
    CAGE / http://www.alcyone.com/pyos/cage/
 A cellular automaton simulation system in Python.




More information about the Python-list mailing list