We help IT Professionals succeed at work.

Printing in Java Using Runtime.exec

SureshVeera
SureshVeera asked
on
Hai
I have to print a file in windows (in local printer)using Runtime.exec method.I tried it using the conventional command of copy <filename> lpt1 /b .but it shows error.Is it possible to do the above.If so pls let me know.
Thanx in Advance...
V.Suresh
Comment
Watch Question

Hi
 As far as I know 'copy' is an internal comand of windows command shell (cmd on NT/2000 or command on Win95/98) so the way to call it from Runtime.exec is

   cmd /c copy <filename> lpt1 /b (on NT, it should work with command instead of cmd on 98/95 )
 
Hope this helps
Commented:
You could also use the "print" command:

  print <filename>


If you know the name of the printer device, you can specify that as well:

  print /D:<device> <filename>

If you don't specify a device, it will go to the default printer..

This would be a better approach, since LPT1 doesn't always exist (I don't have one;  all my printers are USB...)
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- split points between karlinsky and nebeker

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
karlinsky, points for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20633872.html

per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Explore More ContentExplore courses, solutions, and other research materials related to this topic.