This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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..
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
Joined: Aug 26, 2002
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
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...
Joined: Aug 26, 2002
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
Author and all-around good cowpoke
Joined: Mar 22, 2000
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