import java.io.*;
import java.io.IOException;
import java.util.Scanner;
public class AutoStart{
public static void main(String[] args){
while(true){
Runtime r = Runtime.getRuntime();
try{
Process p = r.exec("ps -ef >> services.txt");
try{
p.waitFor();
} catch(InterruptedException e){
e.getStackTrace();
}
Scanner txtscan = new Scanner(new File("services.txt"));
int running = 0; //0 means not running and 1 means running
while(txtscan.hasNextLine()){
String str = txtscan.nextLine();
if(str.indexOf("red5") != -1){
running = 1;
}
}
if(running == 0){
//red5 is not running so start it now
//code to start it goes here
}
//at the end remove services.txt file
//code to remove that file goes here.
} catch(IOException e){
e.getStackTrace();
}
try {
Thread.sleep(1000); //1000 milliseconds is one second.
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
On line 10 I am trying to create a text file which contains list of all the running programs but my java program is not able to create it.
This program is not able to create services.txt file and I don't get any error at all so I am confused what's the problem. Can you help me figure out the problem? Thank you.
>> xxxis interpreted by the command interpreter; but here those are arguments to thepscommand which, of course, knows nothing of them.).