From: Richard Ryan Date: 2002-08-18T03:58:51+09:00 Subject: Re: How do I dup file descriptors in ruby? (diverting STDERR) Dave Thomas writes: > Richard Ryan writes: > > > Thank you for the suggestion, but perhaps I should have been more > > specific about what I really want to do. The following is closer to > > what I'm interested in. It's a very common lick to play in Korn, > > perl and C and if I have to go through a symphony to do the same > > thing in ruby then, to paraphrase the great American poet Chuck > > Berry, I'll lose the beauty of the melody. > > Is this along the right lines? > > old_stdout = $stdout.clone > old_stderr = $stderr.clone > $stdout.reopen("stdout", "w") > $stderr = $stdout > puts "Hello world" > system "ls -l a*" > system "ls non_existent_file" > $stdout = old_stdout > $stderr = old_stderr > puts "done" > > > Cheers > > > Dave Hi, Yes, those are right along the lines I was thinking, and that actually was the first thing I tried but, and maybe I'm being too picky, if I put that through irb and check $stderr.fileno I get something other than 2. That really kind of bugs me for some reason. It just don't seem right. Thanks again for any help you can give, Richard Ryan