$stdout to printer

View: New views
12 Messages — Rating Filter:   Alert me  

$stdout to printer

by Dimas Cyriaco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Still trying to print stuff...
someone knows how to redirect $stdout to a printer??

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


Re: $stdout to printer

by tomcloyd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dimas Cyriaco wrote:
> Still trying to print stuff...
> someone knows how to redirect $stdout to a printer??
>
> Thanks!
>  
Have been researching this, and not coming up with much. However, I'm
getting a strong sense that we need to know your OS.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@... >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Re: $stdout to printer

by Eleanor McHugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 3 Jul 2009, at 22:15, Tom Cloyd wrote:
> Dimas Cyriaco wrote:
>> Still trying to print stuff...
>> someone knows how to redirect $stdout to a printer??
>>
>> Thanks!
>>
> Have been researching this, and not coming up with much. However,  
> I'm getting a strong sense that we need to know your OS.

On most platforms the printer will be mapped to a device file by the  
operating system, and this device file can be opened from Ruby like  
any other regular file. Of course as to whether or not plain text  
dumped to this file will result in the expected printed output is open  
to question: for example a PostScript printer may well expect the  
content written to the file to be a valid PostScript program.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason



Re: $stdout to printer

by tomcloyd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dimas Cyriaco wrote:
> Still trying to print stuff...
> someone knows how to redirect $stdout to a printer??
>
> Thanks!
>  
Here's a path which may solve a lot of problems for you - Ruby Ruports -
http://rubyreports.org. Looks flexible, and it appears that a lot of
thought and work has gone into this tool.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@... >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Re: $stdout to printer

by Dimas Cyriaco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tom Cloyd wrote:

> Dimas Cyriaco wrote:
>> Still trying to print stuff...
>> someone knows how to redirect $stdout to a printer??
>>
>> Thanks!
>>  
> Have been researching this, and not coming up with much. However, I'm
> getting a strong sense that we need to know your OS.
>
> t.
>
> --
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
> Bellingham, Washington, U.S.A: (360) 920-1226
> << tc@... >> (email)
> << TomCloyd.com >> (website)
> << sleightmind.wordpress.com >> (mental health weblog)
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm using windows.
I manage to get the printer`s name using wxruby's PrintDialog, and tried
to redirect $stdout to it, but it doesn't work...
In fact i'm trying to print a report made using Ruport. But i did not
find a way to do that inside ruport...
--
Posted via http://www.ruby-forum.com/.


Re: $stdout to printer

by Dimas Cyriaco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Anyone?
--
Posted via http://www.ruby-forum.com/.


Re: $stdout to printer

by Eleanor McHugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 6 Jul 2009, at 19:56, Dimas Cyriaco wrote:
> Anyone?

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


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason



Re: $stdout to printer

by Brian Candler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dimas Cyriaco wrote:
> I'm using windows.
> I manage to get the printer`s name using wxruby's PrintDialog, and tried
> to redirect $stdout to it, but it doesn't work...

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)

> In fact i'm trying to print a report made using Ruport.

It's a long time since I fought with Ruport and its awful API, but I did
document what I found out on the Wiki. Here it is:

http://stonecode.svnrepository.com/ruport/trac.cgi/wiki/DimwitsGuide

If Ruport currently returns the report to you as a string, then just:

  report = .... do something with Ruport ...
  File.open("out.txt","w") { |f| f.write(report) }

But it should be possible to tell it to write directly to a file, by
passing :io as an option to the relevant rendering call. Something like
this:

   ro = { .. rendering options .. }
   fmt = :html
   File.open("out.txt", "w") { |f| report.as(fmt, {:io=>f}.merge(ro)) }

HTH,

Brian.
--
Posted via http://www.ruby-forum.com/.


Re: $stdout to printer

by Brian Candler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

All this assumes you can open a channel to your printer from Ruby.
Options you could try, as I'm afraid I don't have a Windows box with a
printer:

(1) File.open("prn:","w") { |f| ... }

(2) IO.popen("print","w") { |f| ... }

(or whatever the command-line tool is for printing a file)

(3) Write the report to a file, then you *must* be able to print it
somehow.

  system("print out.txt")
  system("type out.txt >prn")
  ... ?
--
Posted via http://www.ruby-forum.com/.


Re: $stdout to printer

by Bertram Scharpf :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Am Dienstag, 07. Jul 2009, 20:10:53 +0900 schrieb Brian Candler:
> (1) File.open("prn:","w") { |f| ... }
> (2) IO.popen("print","w") { |f| ... }

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

Sorry, I can only test and will only provide the UNIX version.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de


Re: $stdout to printer

by Gilbo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jul 7, 2:32 pm, Bertram Scharpf <li...@...> wrote:

> Hi,
>
> Am Dienstag, 07. Jul 2009, 20:10:53 +0900 schrieb Brian Candler:
>
> > (1) File.open("prn:","w") { |f| ... }
> > (2) IO.popen("print","w") { |f| ... }
>
> 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
>
> Sorry, I can only test and will only provide the UNIX version.
>
> Bertram
>
> --
> Bertram Scharpf
> Stuttgart, Deutschland/Germanyhttp://www.bertram-scharpf.de

Not sure about redirecting stdout on windows, best i can see is that
you redirect to a temp file
and print that.

if the file is a recognised type on windows (e.g. .pdf and adobe
reader is installed)
try this :
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"



Re: $stdout to printer

by Dimas Cyriaco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> 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/.