Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2004

Tip: Looking for answers? Try searching our database.

Execute external program from tomcat servlet

Thread view: 
Fredrik - 28 Sep 2004 22:46 GMT
I want to execute external programs (in this case batch-files)
server-side, and capture the output. I've read about Runtime.exec and
the different problems with reading the input stream.
Despite having tried a bunch of examples, I haven't been able to get
any of them to work when executed by tomcat (running as a service on
win2003svr, user "local system account" ).
As a stand-alone java program there is no problem executing the
batch-file. What could be the cause of my problem?
Andrew Thompson - 28 Sep 2004 23:04 GMT
> ...What could be the cause of my problem?

<with head tilted>
To fix that NotEnoughFluffyKittensException,
simply use the web-context cats='letthembreed'.
</with head tilted>

If that does not fix the problem, you might try
stating exactly what the exception or error is.
<http://www.physci.org/codes/javafaq.jsp#exact>

I would also be helpful if you provide a self-contained
example of your code that does not work.
<http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.lensescapes.com/  Images that escape the mundane

Fredrik - 29 Sep 2004 07:32 GMT
I didnt't get an exception. That would make things alot easier.
I didn't include any code since i've tried almost every example that i
could find, with the same result: _nothing happens_  The external
program never seems to get executed.
I've tried everyting from simple ones like

 try {
    String line;
    Process p = Runtime.getRuntime().exec(cmdline);
    BufferedReader input = new BufferedReader
        (new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
      System.out.println(line);
      }
    input.close();
    }
   catch (Exception err) {
    err.printStackTrace();
    }
 }

,to complete multi-threaded helper classes such as
http://www.codeproject.com/useritems/ProcessHelper.asp

Both of them works splendid when executed as standalone java, but not
from tomcat.
I didn't include them because i thought this was a "theroretical"
problem with running external programs from java programs running as a
windows service, not a code-error.

Please excuse my bad English.

> > ...What could be the cause of my problem?
>
[quoted text clipped - 10 lines]
> example of your code that does not work.
> <http://www.physci.org/codes/sscce.jsp
Andrew Thompson - 29 Sep 2004 10:03 GMT
>>> ...What could be the cause of my problem?
..
>> I would also be helpful if you provide a self-contained
>> example of your code that does not work.
>> <http://www.physci.org/codes/sscce.jsp>

> I didnt't get an exception. That would make things alot easier.
> I didn't include any code since i've tried almost every example that i
[quoted text clipped - 3 lines]
>
>   try {

Put something there that is 'self-contained' and I will try it..
...
> http://www.codeproject.com/useritems/ProcessHelper.asp

Wants a log-in..

> Both of them works splendid when executed as standalone java, but not
> from tomcat.

Logs!

> I didn't include them because i thought this was a "theroretical"
> problem with running external programs from java programs running as a
> windows service, not a code-error.

I do not know enough to say, but you are going to need
to get the server gurus in on this one.

> Please excuse my bad English.

You're English is fine, but please make sure you read the
URL's I give you, the code you supplied above was not what
I described in the link.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.lensescapes.com/  Images that escape the mundane



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.