linux - How to run infinte loop shell script from a java program -


I want to run a shell script from a java program. When I'm running in the terminal and my short script (loop_should.sh) is working fine like my Java program (Execute.java), then running with other commands like 'LS' etc. is working fine. But when I try to run the shell script, the java program, shell script is not printing the values ​​that are inside a loop. These are the codes for both the shell script and the java program respectively.

loop_shell.sh: -

  # bin / sh i = 0 j = 0 timer = 0; Echo "u r in loop_shell.sh" while ((i! = 1)); "Waiting for folder" echo "  

Execute.java: -

  import java.io.buffferedReader; Import java.io.IOException; Import java.io.InputStream; Import java.io.InputStreamReader; Import java.io.file; Public class executed {public static zero main (string array []) {string command = ". / Loop_shell.sh"; String output = exempt command 1 (command); Println (production); } Public stable string execution command 1 (string command) {stringbuffer output = new stringbuffer (); Process P; {File dir = new file ("/ home / vamz / desktop / sudhir_personal / java_important /"); // path p = RuntimeTet Timetime (). Try Exec (Command, Blank, DIR); P.waitFor (); Buffer Reader = New buffed reader (neweststream reader (PJet InputStream ())); String line = ""; While ((line = reader. Readline ()) = null) {output.append (row + "\ n"); }} Hold (exception e) {e.printStackTrace (); } Return output.toString (); }} Expected output: -  
  ur Loop_shell.sh in ur loop_shell.sh ur loop_shell.sh in ur loop_shell.sh ur loop_shell.sh ur in loop_shell.sh in .......... so on ....  < / Pre> 

If you try to run both programs, then u will get the same output. I can see that the output is just printing "ur r in loop_shell.sh" and to complete the shell script Waiting for! Can anyone tell me what's going on? And pls tell me how to run infinte loop script from a java program.

After searching for the Internet and scratching, my head was permanently deleted from a java program Shell script detected correctly to run. My Java program should be like this: -

  Import java.io.buffferedReader; Import java.io.IOException; Import java.io.InputStream; Import java.io.InputStreamReader; Import java.io.file; Public class executed {public static zero main (string array []) {string command = "/ bin / bash loop_shell.sh"; ---- & gt; Shell command changes! String output = exempt command 1 (command); Println (production); } Public stable string execution command 1 (string command) {stringbuffer output = new stringbuffer (); Process P; {File dir = new file ("/ home / vamz / desktop / sudhir_personal / java_important /"); // path p = RuntimeTet Timetime (). Try Exec (Command, Blank, DIR); P.waitFor (); Buffer Reader = New buffed reader (neweststream reader (PJet InputStream ())); String line = ""; While ((line = reader. Readline ()) = null) {output.append (row + "\ n"); }} Hold (exception e) {e.printStackTrace (); } Return output.toString (); }}   

As you can see, the Bash command should be like "/ bin / bash / loop_shell.sh". Now my Java program is waiting for the shell script to be completed !!

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -