On Sat, May 10, 2003 at 11:55:21PM +0900, ts wrote:
> >>>>> "M" == Michael Campbell <michael_s_campbell / yahoo.com> writes:
> 
> M> I take it by your response, Ruby doesn't do this...?
> 
>  ruby do exactly the same, this is why I've not understood this part of the
>  RCR 

My apologies, I had misinterpreted the behaviour, and I see you are right:

irb(main):007:0> %x{asdfasdf 2>&1}
asdfasdf: not found
=> ""
irb(main):006:0> %x{asdfasdf}
(irb):6: command not found: asdfasdf
=> ""

Note the extra "(irb):6: command not found" in the second case; this is the
giveaway that the command is run without a shell. It's a Ruby-generated
message (with a ruby line number) not a shell-generated message.

But in both casees, the command generates output to your Ruby program's
stderr:

  $ cat x.rb
  a = %x{nonexist1}
  p $?
  b = %x{nonexist2 2>&1}
  p $?

  $ ruby x.rb 2>foo
  32512
  32512

  $ cat foo
  x.rb:1: command not found: nonexist1
  nonexist2: not found

The error 'command not found' seems to say 'exception!' to me, but thinking
about it now I suppose it's better to be consistent than to have exceptions
in some error situations and empty strings in other cases.

But at least I'd like to have a way to either capture this message into the
result string, or discard it, preferably without message about with STDERR
itself (which is what triggered this whole discussion off!)

Cheers,

Brian.