> What OS are you using? What printer do you want to output to? Do you
> know the device name of the printer?

I'm using windows.
I actually like the user to choose the printer. I can get the printer 
name with wxRuby's 
PrintDialog#get_print_dialog_data.get_print_data.get_printer_name.

>So how did you attempt to redirect $stdout to it? From within Ruby? 
>(Show the code) From a batch file which runs your Ruby script? (Show the 
>code)

I have tried to redirect $stdout to this name, but don't know if that's 
suposed to work...

Brian Candler, i have already writed the ruport data to a file 
(test.pdf). I'm having trouble passing this file to the printer.

>The original question was how to redirect $stdout.
>
>  def print_it
>    IO.popen "lpr -o some_option", "w" do |f|
>      $stdout = f
>      yield
>    end
>  ensure
>    $stdout = STDOUT
>  end

I will try that. Thanks

>require 'win32ole'
>SHELL_APP = WIN32OLE.new('Shell.Application')
>SHELL_APP.ShellExecute("test.pdf", '', "C:\\Temp", 'print', 0)
>
>otherwise you can try printing to a shared network printer:
>PRINTER = "\\\\192.168.1.1\\shared_printer"
>system "print /d:#{PRINTER} C:\\Temp\\test.txt"

I have tried both. I was able to print with these, but after the 
printing they leave a blank Adobe Reader window open. I tried to change 
last argument of the ShellExecute, but it doesn't work.
It's the solution i'm using at the moment, but it's not working 
properlly.

Thanks everybody!
-- 
Posted via http://www.ruby-forum.com/.