Try{Process P=runtime.getruntime (). exec ("chmod 777/home/bomb/movetoy/webroot/a.sh" ); P.waitfor (); Process Pro= Runtime.getruntime (). exec ("/home/bomb/movetoy/webroot/./a.sh" +num); Pro.waitfor (); System.out.println ("run"); Java.io.InputStream out=Pro.getinputstream (); inti; String a= ""; String b= ""; intN=0; ArrayList<String> tmp =NewArraylist<string>() ; while((i = Out.read ())! = 1) { CharC= (Char) i; if(i==10) { //System.out.println (a);Tmp.add (a); A=""; Continue; } if(i!=13&&i!=10) { //System.out.println (n++ + ":" +c+ "" +i ");A + =c; } } intlen=tmp.size (); //Extracting dissipation valuesString [] tmphaosan=NewString [len]; for(i=0;i<len;i++) {tmphaosan[i]=tmp.get (i). Split ("") [1]; //System.out.println (tmp.get (i). split ("") [1].split ("\\n") [0]);} String ans=""; String Anss=""; for(i=1;i<len;i++) {ans=""; String T1=tmp.get (i-1). Split ("") [0]; String T2=tmp.get (i). Split ("") [0]; for(intJ=0;j<t1.length (); J + +) { //Make sure the space is behind if(t2.charat (j) = = ' E ') { //System.out.println (j+1+ "" +t1.charat (j) + "" +t2.charat (j));ans= (j+1) + "," +ans; } if(t1.charat (j) = = ' E ') {ans+ = (j+1); Ans+=","; }} ans+=tmphaosan[i]; Ans+ = '; '; Anss+=ans; } //System.out.println (anss);PrintWriter PW =Response.getwriter (); Pw.write (anss); } Catch(Exception E) {System.out.println (num); E.printstacktrace (); }
A child process is generated from the runtime class, waiting for the child thread to complete Execution. And the output of the external program is read by intercepting the standard output Stream.
Java Execute shell/cmd command