0

i'm trying to execute a shell script from a j2ee application (made with flash builder 3, spring, apache cxf) et get the result of its execution in my flex interface.

the problem is my application is on a windows 7 station and i don't know how i can execute the script on a distant unix server & get back the result.

i know that ssh apis can help but i've no idea how to get back the result.

any help will be welcome.

thanx

sm1988
  • 71
  • 1
  • 2
  • 4

3 Answers3

1

If you have ssh installed on your windows machine, you should be able to execute a command like

ssh user@remote_host ipconfig

This will execute ipconfig on the remote_host as user "user". You will need to do a bit of research into ssh so that you can make it so you can log in without using a password, but google will help with that.

Alternatively you could look in to a java implementation of ssh - jssh for example, although I confess that I have no experience of using that package.

DaveH
  • 7,187
  • 5
  • 32
  • 53
  • thanx for ure reply. but can i know if all i need to do is putting this cmd in the ' Process p = Runtime.getRuntime().exec(cmd);'? i also don't have ssh installed in my windows machine, do i need to install a specific version according the unix server? – sm1988 May 09 '11 at 09:58
  • I think any ssh client is likely to be OK, unless your unix server is running an extremely old version of the OS. In your position I think that I would investigate using a pure java SSH library though as they may take away some of your configuration headaches - and it's likely to make your deployment easier in the future as well. – DaveH May 09 '11 at 10:08
  • Can you deploy code on the Unix server in question? If yes, you could always put the code that you have above on the unix server ( in a servlet for example ) and then speak to that servlet via HTTP. – DaveH May 09 '11 at 10:14
1

To execute program from windows to unix you really need ssh or telnet.

SSH is more secure. You can do this without running external process. Use one of available pure java SSH libraries (e.g. javassh.org).

See examples. If you use this library your task is trivial. Just call appropriate API.

AlexR
  • 114,158
  • 16
  • 130
  • 208
0

About the only reasonable and reasonably secure answer I could come up with is to configure ssh on both machines. *nix boxes usually have ssh server installed by default. Putty terminal emulation for windows comes with neat ssh client command line utility called plink which can execute shell commands on a remote unix box in a secure manner.

James Anderson
  • 27,109
  • 7
  • 50
  • 78