[Tutor] Re[2]: [Tutor] Re[2]: [Tutor] ksh and SAS questions

Michael P. Reilly arcege@shore.net
Mon, 7 Jun 1999 18:20:41 -0400 (EDT)


TomJenkins@zentuit.com (Tom Jenkins) asks:
> Hi Mike, just curious if this is a typo...
> 
> >   # source the ksh script and output the CATI variable
> >   # with the double quotes in echo, we'll get a last line no matter
> >   # what implimentation of echo or shell
> >   sh_cmd = '. /op/ctl/prod/scripts/setcm.ksh 2>/dev/null; echo "${CATI}"'
> 
> should sh_cmd be = '. /op/ctl/prod/scripts/setcm.ksh $2>/dev/null; echo 
> "${CATI}"'? (notice the $ before 2)

No, the '2>/dev/null' is to redirect standard error to the bit bucket.
Inserting the dollar sign would make it evaluated within the popen
(inside /bin/sh in most cases), where there are no arguments ($2 ==
arg2, but not sys.argv[2]).  You would end up with

  '. /op/ctl/....  >/dev/null; echo ...'

which is not what you want.  In popen, the stderr stream does not get
redirected; if there were error messages from setcm.ksh, they would
still be seen, Python could not capture them.  Redirecting stderr in
the popen avoids that.

Unfortunately, there are few nicely portable methods to redirecting
standard error.  I wasn't going to get into that tho. :)

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------