• Post Reply Bookmark Topic Watch Topic
  • New Topic

Executing programs

 
Joe Wolf
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive my inexperience, but given an input from a client, can a servlet take that input and execute a program residing on the server-side? Just for an example, a webpage comes up with a button that says "Click to run Servletrunner" and the user clicks on it and the /usr/local/jsdk/bin/servletrunner daemon is started through the servlet somehow.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't imagine why you would do that particular example, but yes, a servlet can essentially do anything a freestanding application can do. Most servlets books, including mine, have examples.
You have to use one of the java.lang.Runtime exec methods, get a process, and handle the input and output streams from the process. Kind of hard to debug from the servlet so I recommend you put the process in a helper object and test it stand-alone first.
Bill
------------------
author of:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!