I tried to execute a shell command in Java, but it's not working.
I can directly run this command on Linux(Ubuntu):
/bin/sh -c 'while true ; do java -jar /home/user/workspace/TCPClientNew/WebContent/NewClient.jar 192.168.138.1 6789 ; sleep 1 ; done' but when I do this with Java, it never executes. It always shows "Not Found". Here is my code:
Runtime rt = Runtime.getRuntime(); Process proc; String[] commands = {"/bin/sh","-c","'while true ; do java -jar /home/user/workspace/TCPClientNew/WebContent/NewClient.jar "+" "+host+" "+port+ " ; sleep 1 ; done'"}; proc = rt.exec(command); Can someone tell me why it's wrong? Thank you very much.