How do I write raw printer code to a windows printer share from ruby?
Question
Using java, minus the exception handling, it is as simple as
FileOutputStream ostream = new FileOutputStream("\\\\host\\share");
PrintStream printStream = new PrintStream(ostream);
printStream.print("HELLO PRINTER");
printStream.close();
ostream.close();
Solution
File.open("\\\\host\\share") do |f|
f.print("HELLO PRINTER#{12.chr}")
end
OTHER TIPS
While I've never tried to print from Ruby, and while I don't have a Windows machine available to test on, it would seem to me that you don't want to be using the File
class, but instead the IO
class. 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 too helpful, let me know why.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow