Search code examples
javaautosys

Java program for retrieving autosys status


Please tell me how to retrieve the status of autosys command from java program. we can execute the commands using Runtime.getRuntime().exec(command) but how to get autosys status.


Solution

  • I am not sure about the autosys commend but if you can execute using the Runtime then you need to see the output of execution of command. If autosys will return something upon execution you will get it in out InputStream or error in ErrorStream in case of error.

    Try something like this:

    public static void printStream(InputStream is, String type){
    try
       {
          InputStreamReader isr = new InputStreamReader(is);
          BufferedReader br = new BufferedReader(isr);
          String line=null;
          while ( (line = br.readLine()) != null)
                System.out.println(type + ">" + line);    
       } catch (IOException ioe){
               ioe.printStackTrace();  
       }
    }
    
    public static void main(String args[])
    {
        String cmd = "command to execute";
        Process proc = Runtime.getRuntime().exec(cmd);
        printStream(proc.getInputStream(), "OUTPUT");
        printStream(proc.getErrorStream(), "ERROR");
    }