How to output result to text file?

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.

Hi,

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

···

From: "nkb" <nkb@pacific.net.sg>

Bill Kelly wrote:

Hi,

From: "nkb" <nkb@pacific.net.sg>

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.

Is the code is writing to STDERR?

The you would need

ruby mytestscript.rb 2> output.txt

James

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

···

ruby mytestscript.rb 2> output.txt

James

nkb wrote:

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

:slight_smile: 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

···

Thanks!

ruby mytestscript.rb 2> output.txt

James

"Hal Fulton" <hal9000@hypermetrics.com> schrieb im Newsbeitrag
news:41511032.3000904@hypermetrics.com...

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

:slight_smile: 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. :slight_smile:

    robert