Printing using system commands from Tomcat as a service

2010-10-12 Thread F2Andy

Using Ruby on Rails on Tomcat, I want to sent a file to a printer, which
should be easy via a system command. It works if I run Tomcat from the
command line, but not if Tomcat is running as a service.

Some details...

I am using Tomcat 6 on Windows Server 2003, Rail 2.3.9, JRuby 1.5.2 (I
appreciate most people around here will not be familar with Ruby on Rails,
but I think this is a Tomcat problem, not a RoR problem). I am trying to
deploy an application in which records can be printed to a label printer. To
print, it creates a new file, which is then copied to lpt4: (which is
actually a USB port on a networked computer, via net use) with a system
command:
copy C:\tomcat-6\webapps\print\WEB-INF\print.txt lpt4

This works fine in development (using Webrick as the web server), but I
found it does not work when I try to deploy to production (i.e., using
Tomcat on the same physical machine). The message returned from the OS is 0
file(s) copied, nothing more helpful than that. The command looks fine, and
indeed, I can copy the command and paste it into the command prompt, and the
label is spat out. Clearly the file is being created and saved properly, and
the file is formatted okay for the printer to understand.

However, when I run Tomcat from the command prompt (tomcat6), it does work
(and this is using the same Tomcat installation, by the way).

My first guess was a permissions issue, so I had the Tomcat service using
the admin account, but still nothing.

Anyone any suggestions for what the problem might be? At this stage, I am
not even sure where to look.
-- 
View this message in context: 
http://old.nabble.com/Printing-using-system-commands-from-Tomcat-as-a-service-tp29942098p29942098.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Printing using system commands from Tomcat as a service

2010-10-12 Thread Pid
On 12/10/2010 11:57, F2Andy wrote:
 
 Using Ruby on Rails on Tomcat, I want to sent a file to a printer, which
 should be easy via a system command. It works if I run Tomcat from the
 command line, but not if Tomcat is running as a service.
 
 Some details...
 
 I am using Tomcat 6 on Windows Server 2003, Rail 2.3.9, JRuby 1.5.2 (I
 appreciate most people around here will not be familar with Ruby on Rails,
 but I think this is a Tomcat problem, not a RoR problem). I am trying to
 deploy an application in which records can be printed to a label printer. To
 print, it creates a new file, which is then copied to lpt4: (which is
 actually a USB port on a networked computer, via net use) with a system
 command:
 copy C:\tomcat-6\webapps\print\WEB-INF\print.txt lpt4
 
 This works fine in development (using Webrick as the web server), but I
 found it does not work when I try to deploy to production (i.e., using
 Tomcat on the same physical machine). The message returned from the OS is 0
 file(s) copied, nothing more helpful than that. The command looks fine, and
 indeed, I can copy the command and paste it into the command prompt, and the
 label is spat out. Clearly the file is being created and saved properly, and
 the file is formatted okay for the printer to understand.

How are you constructing the command and calling it?

Are you setting up the environment to match your environment in the
command prompt?


p

 However, when I run Tomcat from the command prompt (tomcat6), it does work
 (and this is using the same Tomcat installation, by the way).
 
 My first guess was a permissions issue, so I had the Tomcat service using
 the admin account, but still nothing.
 
 Anyone any suggestions for what the problem might be? At this stage, I am
 not even sure where to look.



0x62590808.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature


Re: Printing using system commands from Tomcat as a service

2010-10-12 Thread Peter Crowther
On 12 October 2010 11:57, F2Andy andy.j...@f2chemicals.com wrote:

 To
 print, it creates a new file, which is then copied to lpt4: (which is
 actually a USB port on a networked computer, via net use)

 Exactly where and when is the net use running?  There are two key points
with Windows services:

1) A service starts with its own copy of the environment, so even if it is
running as the same user as the console user it does not share drive or
device mappings;

2) A service does not get a fully-processed copy of the environment, so
drive and device mappings are not restored from the environment.

So:

a) Make sure your Tomcat service is running as a user that is known to the
network (not Local service, Local system or an account that is local to
the server), otherwise your service will be unable to authenticate to the
machine with the printer;

b) Write yourself a batch file that does the net use and the copy, and
invoke *that* from your system command.

Hope this helps you resolve the problem!

- Peter