This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes runtime exec a process on another server using a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "runtime exec a process on another server using a servlet" Watch "runtime exec a process on another server using a servlet" New topic
Author

runtime exec a process on another server using a servlet

maneesh subherwal
Ranch Hand

Joined: Aug 26, 2002
Posts: 42
Hello,
I was wondering if it was possible to runtime exec a process on another server.
For instance I am on server one and I have accessible rights to server two. I would like the user to call a servlet on server one that executes a process on server 2. How would I go about doing this?
Any help would be appreciated...
Thank you,
Maneesh
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
client (probably with browser) --> servlet1-server1--->servlet2@server2
If this is the case; @servlet1 create a URL Object with target to URL of server2-servlet2...
but I am not sure yet..
please try and inform..
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
If you can have a process on server 1 execute a process on server 2 then it can be done with a servlet on server 1. Have you read the API for the various java.lang.Runtime exec() methods?
Bill


Java Resources at www.wbrogden.com
maneesh subherwal
Ranch Hand

Joined: Aug 26, 2002
Posts: 42
I reviewed the API but am still unsure about doing this.
yes, that is correct. I am trying to access the servlet from a browser that will then call a process on server 1 which should call a process on server 2.
any further information...
Thank you,
Maneesh
Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
Maybe this helps:
To call a Servlet from Java (Another servlet or any Java code) you could use this:

You are working with Java, so you can send anything to the servlet (like an Objet), not just a URLEncoded string.
If you just want to do a GET (previous was a POST), you can change :

to exec the process :


Hope this helps...
maneesh subherwal
Ranch Hand

Joined: Aug 26, 2002
Posts: 42
also, there is no servlet on server 2. This server only has processes running on it and this process would need to run somehow...
browser-->servlet1-->serverProc1-->server2-->serverProc2
Thank you,
Maneesh
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
I suggest you experiment with the Runtime exec methods outside the servlet environment first. There are a lot of things that can go wrong and mixing in all the things that can go wrong with servlets does not help.
Important points:
Read the api for java.lang.Process carefully.
You will need to capture the output of the resulting process using Threads that read the stdout and stderr streams. If you don't read these streams, the process may freeze-up mysteriously.
Bill
Gopi Balaji
Ranch Hand

Joined: Jan 23, 2003
Posts: 84
A possibility -
If server2 supports the telnet protocol, open a telnet session from servlet1 in server1 (or a helper class thereof) and execute the process in server2.

-GB.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: runtime exec a process on another server using a servlet
 
Similar Threads
Stopping a servlet
running an executable file on the server by client
putting servlets to sleep
Stopping and Starting Threads
Thread.sleep vs yield (again)