• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Running a command on a remote system

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to run a command on a remote system from a Java application running on another system. Namely I would like to start a Java application on the remote system. Does anybody have any idea on how to do this? Thanks for the help
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In English, you need a server on the remote system that's always listening for requests to start another application. As far as I know, you'll have to write your own although there might be something out there already. A browser performs this functions when it runs applets.
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could write a java program on the server that listens on a particular socket. Your other program would send a message to over that socket to the server program. The message could be a Vector, or String (use the ObjectOuputStream class to serialize your object before sending)
An example of the message would be an ArrayList:
ArrayList[0] = classname
ArrayList[1] = parameter1
ArrayList[2] = parameter2
Now the server program will de-serialize the object sent across, break it apart into its components, and could use reflection to call the class and any of its methods (you could add the method name to another index in the array list and any parameters that that needs also)
Or if the class performs some function, then you may need to investigate the Runtime class also, which would start your java program and then wait for it to complete before accepting any more messages over the socket, otherwise you could probably launch the applications each in a separate thread.
Hopefully this makes a little sense
Brian
 
Sheriff
Posts: 6999
6
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a webserver on the remote system it's a simple matter to knock together a CGI to start any sort of application, java included, and return a "done it" web page. This is the kind of thing the CGI protocol was invented for.
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As much as I'm a Java zealot, there's another option. Computer A is running your first java program. It uses Runtime.exec() to invoke a script on computer A, which connects to computer B, and runs a sequence of commands there, which start the second Java program. This is an option if you'd rather not be running a Java server on the second machine.

--Mark
hershey@vaultus.com
 
Jason Thiesse
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help!! I'll post what I get to work.
 
Jason Thiesse
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is exactly what I'm trying to do!! How do I connect to System B? Is ther any security worries?
Thanks
Jason

Originally posted by Mark Herschberg:
As much as I'm a Java zealot, there's another option. Computer A is running your first java program. It uses Runtime.exec() to invoke a script on computer A, which connects to computer B, and runs a sequence of commands there, which start the second Java program. This is an option if you'd rather not be running a Java server on the second machine.

--Mark
hershey@vaultus.com


 
Mark Savory
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark Herschberg,
How do you connect to computer B?
The previous replys try to make it clear that you need a listner/server on computer B in order to "connect" remotely.
 
Jason Thiesse
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to have a Java server, or any other server running on the the second machine (System B). I would like to connect to the System and exicute a command to start a server. From what I understand of RMI I would have to start the Server on System B ahead of time. Please correct me if I am wrong.

Originally posted by Mark Herschberg:
...This is an option if you'd rather not be running a Java server on the second machine.

--Mark
hershey@vaultus.com


 
Mark Savory
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There has to be a server running on computer B - not neccessarily one that you started. You can Telnet to the remote computer and run a script. In that case a Telnet daemon(basically a server) would have to be running on computer B.
 
Jason Thiesse
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!!

Originally posted by Mark Savory:
There has to be a server running on computer B - not neccessarily one that you started. You can Telnet to the remote computer and run a script. In that case a Telnet daemon(basically a server) would have to be running on computer B.


 
Onion rings are vegetable donuts. Taste this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic