0

Im trying to run a jsp file present in one unix server,which is trying to execute a python present in another unix server by doing ssh through a java code, which I placed inside the scriptlet tag in Jsp file, which has only user name and host IP address and remote path of the python script. My problem is the cmd present present in process variable is not getting executed,it is entering the try block but not executing the cmd .Is there any way to correct it. Please any one Help me out.

Below is my code

try {
Process p = Runtime.getRuntime().exec("loginusername loginusername@hostipaddress /path/python.py");
BufferedReader in = new BufferedReader(
                                new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) 
           {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
happy
  • 3
  • 8
  • what is `loginusername` supposed to do ? If there is no program with this name your exec call will fail. – Marged Oct 19 '15 at 05:23
  • @Marged when we login into the unix machine,( where we have the code)loginusername is made use,for example: Process p = Runtime.getRuntime().exec("abc abc@hostipaddress /path/python.py");,then only we will be able to fetch the code and excute the file present at host – happy Oct 19 '15 at 05:34
  • So this abc program exists and this command works when run from the shell ? – Marged Oct 19 '15 at 05:56
  • @Marged Yes , I am doing ssh via java code(present in one unix machine) to another unix machine, after connection is established i have to invoke and execute a python script present there and fetch values.But im unable to connect or do ssh ,so cmd present inside the Runtime.getRuntime.exec is not working :( , Is there any other way to connect and invoke the script.Please help – happy Oct 19 '15 at 06:15
  • I think your question has been answered many times before, have a look here: http://stackoverflow.com/questions/2514439/how-do-i-run-ssh-commands-on-remote-system-using-java or do your own search if you need a different approach – Marged Oct 19 '15 at 06:18
  • @Marged Thanks for posting the link, will try it out and let you know soon – happy Oct 19 '15 at 06:35

0 Answers0