Hi, I am trying to call a shell script from Java and I am not sure how can I find out whether the script ran sucessfully or not. Shell Script:ftpscript.sh ftp -n testServer << EOD user userName Password bin cd /Reports put rpt1.csv quit Java Code Snippet ----------------- Runtime myRuntime = Runtime.getRuntime(); String cmd = "command ftpscript.sh"; Process ps = myRuntime.exec(cmd); ps.waitFor(); ps.destroy(); System.out.println("Exit Status: " + ps.exitValue() + " " + ps.toString()); Lets say user password is invalid, in that case ftpscript.sh will unable to ftp the file but from Java point of view I am getting Exit Status as ZERO (Prociess.exitValue()). Any ideas how to know whether FTP script was sucessful or not. Thanks. SK
Yes -- rewrite the ftp script to return an error status when it fails! You might have the script test for the existence of the file by running the ftp "ls" command on the server, and piping the result through "grep". Be careful because grep returns non-zero on success, zero on failure!
Otherwise you have to use the javax.sentience package (JSR-10023) which won't be ready for another 20 years or so.