1

Someone can tell me the best way, through a web Java application, how to run an application on a remote machine (linux) and how to know if this application has already completed. I know the application terminates automatically, so just wanted to wait for the answer.

any help or advice are very welcome.

coffee
  • 3,048
  • 4
  • 32
  • 46
  • 2
    You might be able to connect via SSH. You can use the command line or a Java library for SSH. – Peter Lawrey Jun 15 '11 at 19:03
  • @YGomez @Peter Like this: Process p = Runtime.getRuntime().exec("here I need to connect(ssh with passw) and send my command"); Is it right? – coffee Jun 15 '11 at 19:07

1 Answers1

2

I was confused by the wording, so I will assume the following: the web application and the remote application are running on two different machines, with the remote application on Linux.

If that is the case, then you would be better off using a SSH library for Java (there are several - JSch, sshj, Ganymed SSH-2, to connect to the remote machine and run commands on it. This is a better approach than using ProcessBuilder, for it abstracts you from the problem of providing your password to the terminal (which can get quite tricky).

I'm not sure what you meant by this statement: "I know the application terminates automatically, so just wanted to wait for the answer." so I'll make another assumption that you want to know if the remote process terminated successfully or not. I'm unsure if any of the SSH libraries posted above, will allow you to get the remote process status in a non-trivial way, so you are better off writing a shell wrapper to your remote command that will return a parseable message.

If you are running both on the same machine, use ProcessBuilder.

Community
  • 1
  • 1
Vineet Reynolds
  • 76,006
  • 17
  • 150
  • 174
  • In your opinion, Which is the easiest to use? JSch, sshj, GanumerSSH-2 – coffee Jun 15 '11 at 19:53
  • 1
    Well, if you can understand the examples of JSch, use it. It is known for not being well documented, although Eclipse, maven and few other FOSS projects use it. It might suffice in your case. But if you need to understand the workings under the hood, sshj appears to be a better choice. **Edit:** You ought to read [this opinion piece](http://techtavern.wordpress.com/2008/09/30/about-jsch-open-source-project/). In short, if you hit a problem you can't diagnose, you know it's time to use sshj. – Vineet Reynolds Jun 15 '11 at 19:59
  • Maybe [GSOC](http://stackoverflow.com/questions/995944/ssh-library-for-java/1678190#1678190) – coffee Jun 15 '11 at 20:02
  • 1
    @coffee, GSOC has now become sshj. – Vineet Reynolds Jun 15 '11 at 20:04