How to output result to text file?

N

nkb

Hi.
I would like to pipe the output of a ruby script to a text file. On
unix, I can easily type
mycommand > output.txt

With ruby, I typed
ruby mytestscript.rb > output.txt

The result still prints out to the standard microsoft commandline
console output and not to the file output.txt. How can I achieve the
output to a text file?

Thanks.
 
B

Bill Kelly

Hi,

From: "nkb said:
With ruby, I typed
ruby mytestscript.rb > output.txt

The result still prints out to the standard microsoft commandline
console output and not to the file output.txt. How can I achieve the
output to a text file?

That's odd.... Which version of windows are you running?
On my win2k box,

ruby -e "puts 'hi'" > zz

...creates a file called "zz" with "hi\n" in it as expected.



Regards,

Bill
 
J

James Britt

Bill said:
Hi,




That's odd.... Which version of windows are you running?
On my win2k box,

ruby -e "puts 'hi'" > zz

...creates a file called "zz" with "hi\n" in it as expected.

Is the code is writing to STDERR?

The you would need

ruby mytestscript.rb 2> output.txt

James
 
N

nkb

Fabulous! This works! What exactly does '2' means? Where do I get info
about such thing as '2' or '3' or ??
Thanks!
 
H

Hal Fulton

nkb said:
Fabulous! This works! What exactly does '2' means? Where do I get info
about such thing as '2' or '3' or ??

:) This is a Unix or Linux shellism, unrelated to Ruby as such. Read
about bash or whatever shell you're using.

The '2' comes from the fact that standard error is file descriptor 2
(0 being stdin and 1 stdout).

Hal
 
R

Robert Klemme

Hal Fulton said:
:) This is a Unix or Linux shellism, unrelated to Ruby as such. Read
about bash or whatever shell you're using.

The '2' comes from the fact that standard error is file descriptor 2
(0 being stdin and 1 stdout).

Although some might not believe it, Windows' cmd.exe knows abuout these,
too. So it's not only *nix. :)

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top