
// BasicExec.java
// Andrew Davison, ad@coe.psu.ac.th, Nov. 2022

/* "Java -version" example from zt-exec's website
    (https://github.com/zeroturnaround/zt-exec) but
    using my ZUtils functions and Java built-in features

    Usage:
      > compile BasicExec.java
      > run BasicExec
*/

import java.io.*;



public class BasicExec
{
  public static void main(String[] args)
  {
    String[] cmd = new String[]{"java", "-version"};
    if ( ZUtils.cmdExit(cmd) != 0)
      System.out.println("Java not found");
    else
      System.out.println( ZUtils.cmdOut(cmd) );

    // have a look in Window's installation folders
    if (ZUtils.getOSType() == ZUtils.WINDOWS) {
      String path = System.getenv("ProgramFiles");
      System.out.println("Is \"java\" in \"" + path + "\": " + 
                                   ZUtils.inDir(path, "java"));

      path = System.getenv("ProgramFiles(X86)");
      System.out.println("Is \"java\" in \"" + path + "\": " + 
                                   ZUtils.inDir(path, "java"));
    }

    // get Java's direct answer
    System.out.println("\nJava's version property: " + 
                       System.getProperty("java.version"));
  }
}  // end of BasicExec class