[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby Noob: Using stderr, stdout, etc

reed.adam@gmail.com

3/1/2007 9:38:00 PM

I'm a QA tester currently using ruby/watir for testing web sites/
applications. I've done fairly well so far for our small needs -
automating IE browsing/tasks, assertion results logging (custom
logger), and e-mail notifications for assertion errors.

I would like to log the console output from the ruby program (shown in
either DOS or SciTE) to a file just to have, but I'm not sure if this
is what stderr/stdout is talking about. It seems to be such a well-
known concept that nobody really talks about it in detail on the web.
I know what they are by definition, but beyond that I'm having trouble
finding anything.

Any help/information you can provide is greatly appreciated.

Thanks --

10 Answers

Brian Candler

3/1/2007 10:38:00 PM

0

On Fri, Mar 02, 2007 at 06:40:10AM +0900, reed.adam@gmail.com wrote:
> I would like to log the console output from the ruby program (shown in
> either DOS or SciTE) to a file just to have, but I'm not sure if this
> is what stderr/stdout is talking about. It seems to be such a well-
> known concept that nobody really talks about it in detail on the web.
> I know what they are by definition, but beyond that I'm having trouble
> finding anything.

What platform are you running under - e.g. Windows or Unix?

If it's Unix, then stdin and stdout are well-defined and well-documented. If
it's Windows, then I'm not sure that they are :-)

reed.adam@gmail.com

3/2/2007 1:11:00 AM

0

On Mar 1, 5:38 pm, Brian Candler <B.Cand...@pobox.com> wrote:
> On Fri, Mar 02, 2007 at 06:40:10AM +0900, reed.a...@gmail.com wrote:
> > I would like to log the console output from the ruby program (shown in
> > either DOS or SciTE) to a file just to have, but I'm not sure if this
> > is what stderr/stdout is talking about. It seems to be such a well-
> > known concept that nobody really talks about it in detail on the web.
> > I know what they are by definition, but beyond that I'm having trouble
> > finding anything.
>
> What platform are you running under - e.g. Windows or Unix?
>
> If it's Unix, then stdin and stdout are well-defined and well-documented. If
> it's Windows, then I'm not sure that they are :-)

Windows :D

Tim Becker

3/2/2007 1:18:00 AM

0

> It seems to be such a well-
> known concept that nobody really talks about it in detail on the web.
> I know what they are by definition, but beyond that I'm having trouble
> finding anything.

Hm. Under Unix, processes automatically have three streams/files
attached to them:

"At program startup, three streams are predefined and need not be
opened explicitly: standard input (for reading conventional input),
standard output (for writing conventional output) and standard error
(for writing diagnostic output)."
(http://www.opengroup.org/onlinepubs/007908799/xsh/s...)

By default, stdin is the input coming from the keyboard and stderr and
stdout are output to the terminal the process is running in. This can
be manipulated, though. For example if you want the output of a script
`myprog.rb` to be written into a file named `output` rather than on
the terminal, you redirect the output like this:

$ myprog.rb > output

Under Unix (you'll need to experiment with windows) this only
redirects stdin, which is useful, because you still get to see error
messages and they won't get mixed in with the results of the program.

stdout is also where everything you write with `puts` and `printf` ends up.

Google for something like "unix beginner's tutorial" and search around
in there for terms like `pipe` and `redirection`
-tim


>
> Any help/information you can provide is greatly appreciated.
>
> Thanks --
>
>
>

reed.adam@gmail.com

3/2/2007 3:20:00 PM

0

Thanks for the explanation Tim, that's exactly what I needed. I
didn't realize they would act differently under windows/unix - I think
I was stuck on imagining them as code-specific items because I wasn't
used to hearing about them in unix.

Strangely enough, I'm ok as far as unix and pipe/redirection, and I've
been logging output of standard unix stuff to files for a couple of
years - just never knew specifically what the output was called. Go
figure.

Jenda Krynicky

3/2/2007 7:01:00 PM

0

reed.adam@gmail.com wrote:
> Thanks for the explanation Tim, that's exactly what I needed. I
> didn't realize they would act differently under windows/unix - I think
> I was stuck on imagining them as code-specific items because I wasn't
> used to hearing about them in unix.
>
> Strangely enough, I'm ok as far as unix and pipe/redirection, and I've
> been logging output of standard unix stuff to files for a couple of
> years - just never knew specifically what the output was called. Go
> figure.

The thing to watch out for under Windows is that (at least on some
versions)

script.rb > results.txt

doesn't work and you have to write

ruby script.rb > results.txt

This is caused by the fact that the cmd.exe has to use a different WIN32
API call to execute the script using the file extension mapping than
what it would use for .exe and thatthe former doesn't preserve the
STDxxx redirection.

--
Posted via http://www.ruby-....

Rick DeNatale

3/2/2007 9:39:00 PM

0

On 3/2/07, Jenda Krynicky <jenda@cpan.org> wrote:
> reed.adam@gmail.com wrote:
> > Thanks for the explanation Tim, that's exactly what I needed. I
> > didn't realize they would act differently under windows/unix - I think
> > I was stuck on imagining them as code-specific items because I wasn't
> > used to hearing about them in unix.
> >
> > Strangely enough, I'm ok as far as unix and pipe/redirection, and I've
> > been logging output of standard unix stuff to files for a couple of
> > years - just never knew specifically what the output was called. Go
> > figure.
>
> The thing to watch out for under Windows is that (at least on some
> versions)
>
> script.rb > results.txt
>
> doesn't work and you have to write
>
> ruby script.rb > results.txt
>
> This is caused by the fact that the cmd.exe has to use a different WIN32
> API call to execute the script using the file extension mapping than
> what it would use for .exe and thatthe former doesn't preserve the
> STDxxx redirection.

Also, although I haven't really kept up with windows, it used to be
able to redirect stdout, but not stderr.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Jano Svitok

3/2/2007 10:29:00 PM

0

On 3/2/07, Rick DeNatale <rick.denatale@gmail.com> wrote:
> On 3/2/07, Jenda Krynicky <jenda@cpan.org> wrote:
> > reed.adam@gmail.com wrote:
> > > Thanks for the explanation Tim, that's exactly what I needed. I
> > > didn't realize they would act differently under windows/unix - I think
> > > I was stuck on imagining them as code-specific items because I wasn't
> > > used to hearing about them in unix.
> > >
> > > Strangely enough, I'm ok as far as unix and pipe/redirection, and I've
> > > been logging output of standard unix stuff to files for a couple of
> > > years - just never knew specifically what the output was called. Go
> > > figure.
> >
> > The thing to watch out for under Windows is that (at least on some
> > versions)
> >
> > script.rb > results.txt
> >
> > doesn't work and you have to write
> >
> > ruby script.rb > results.txt
> >
> > This is caused by the fact that the cmd.exe has to use a different WIN32
> > API call to execute the script using the file extension mapping than
> > what it would use for .exe and thatthe former doesn't preserve the
> > STDxxx redirection.
>
> Also, although I haven't really kept up with windows, it used to be
> able to redirect stdout, but not stderr.

I was surprised when I learnt that since win2k it's possible to
redirect stderr and even redirect stderr to stdout or vice versa,
using

progname 2> stderr.txt and progname 2&>1

You know, after all those years, maybe we'll be able to call cmd.exe a shell :D

Other useful bits are:

^ is escape char - for escaping |, > etc.
|| and && work in windows as well


So... reading help might be useful and surprising sometimes...

Stephen Wolstenholme

6/22/2012 9:16:00 AM

0

On Thu, 21 Jun 2012 13:30:36 -0400, NewportsRetro@webtv.net (Steve
Newport) wrote:

>Remember when Don Ameche won?
>

I've never heard of him.

Steve

--
Neural Network Software. http://www...
EasyNN-plus. Neural Networks plus. http://www....
SwingNN. Forecast with Neural Networks. http://www.s...
JustNN. Just Neural Networks. http://www....

Adam H. Kerman

6/22/2012 10:00:00 AM

0

Stephen Wolstenholme <steve@npsl1.com> wrote:
>NewportsRetro@webtv.net (Steve Newport) wrote:

>>Remember when Don Ameche won?

>I've never heard of him.

You've never seen Trading Places, from very late in his career?

He had one of the world's great voices.

He has that leading man look about him, and was a popular movie star in
the '30's and '40s, but had a long career because he didn't have that
stilted leading man acting style that was out of fashion by the end of
the 1930's.

A couple of his more popular pictures were Hollywood biographies
(fictionalized): Story of Alexander Graham Bell and Swanee River

A fun comedy he did was the Lubitsch-Raphaelson Heaven Can Wait, in which
he tells his life story to a sympathetic Devil. (Raphaelson was my father's
uncle.)

He's probably best known for playing John Bickerson on radio, with Frances
Langford as Blanche.

Stephen Wolstenholme

6/22/2012 10:30:00 AM

0

On Fri, 22 Jun 2012 09:59:39 +0000 (UTC), "Adam H. Kerman"
<ahk@chinet.com> wrote:

>Stephen Wolstenholme <steve@npsl1.com> wrote:
>>NewportsRetro@webtv.net (Steve Newport) wrote:
>
>>>Remember when Don Ameche won?
>
>>I've never heard of him.
>
>You've never seen Trading Places, from very late in his career?
>

I've never seen it. It's probably never been on a channel I watch.

Steve

--
Neural Network Software. http://www...
EasyNN-plus. Neural Networks plus. http://www....
SwingNN. Forecast with Neural Networks. http://www.s...
JustNN. Just Neural Networks. http://www....