I have a java app that runs a bash file and inside the bash file i have a code to run another java app and it doesn't seem to work.I come from c++ where this is a very easy task but i'm not really experienced in java. So, here's my code:
import java.io.IOException;
import java.net.*;
import java.util.Scanner;
public class start {
public void executeScript(){
try{
ProcessBuilder pb = new ProcessBuilder("/root/Desktop/chat/script.sh");
Process p = pb.start();
p.waitFor();
System.out.println("Script executed..");
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
start st = new start();
System.out.println("I'm main..");
st.executeScript();
}
}
Here's my bash file:
#!/bin/bash
echo "bash started"
java Client ip_address
echo "bash finished"
Here's the result of this code:
I'm main.. Script executed..
I know "Script executed.." shouldn't print because the java file i'm trying to run from the bash file is an infinite loop.
Note: If i run the bash file separately in the terminal i get an infinite loop which is the intended result and this is why i know that my mistake is from this file.
I hope I made myself clear and if not please ask for more information. Thank you.