How to write printer source code to Windows printer share from ruby?

Using java, minus exception handling, is as easy as

FileOutputStream ostream = new FileOutputStream("\\\\host\\share");
PrintStream printStream = new PrintStream(ostream);
printStream.print("HELLO PRINTER");
printStream.close();
ostream.close();

      

+1


source to share


2 answers


File.open("\\\\host\\share") do |f|
  f.print("HELLO PRINTER#{12.chr}")
end

      



+2


source


While I've never tried typing with Ruby, and while I don't have a Windows machine available for testing, it seems to me that you don't want to use a class File

, but a class instead IO

. You can see its documentation here: http://ruby-doc.org/core/classes/IO.html . It looks like it actually has Windows specific options, so take a look and if it's not overly helpful please let me know why.



+1


source







All Articles