Just use a pipe >
. Worth to look Using command redirection operators.
ruby test.rb > file.txt
Redirection operator and description
>
: Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.
<
: Reads the command input from a file, instead of reading input from the keyboard.
>>
: Appends the command output to the end of a file without deleting the information that is already in the file.
>&
: Writes the output from one handle to the input of another handle.
<&
: Reads the input from one handle and writes it to the output of another handle.
|
: Reads the output from one command and writes it to the input of another command. Also known as a pipe.