/** * XidvcTest. */ import java.io.File; import java.util.regex.Matcher; import java.util.regex.Pattern; import fr.devinsy.util.cmdexec.CmdExec; import fr.devinsy.util.cmdexec.StreamGobbler; import fr.devinsy.util.unix.Unix; import fr.devinsy.kiss4web.*; /** * */ class CmdExecTester { static private org.apache.log4j.Logger logger; static { // Initialize logger. org.apache.log4j.Logger logger = null; org.apache.log4j.BasicConfigurator.configure (); logger = org.apache.log4j.Logger.getRootLogger (); //logger.setLevel (org.apache.log4j.Level.INFO); logger.setLevel (org.apache.log4j.Level.INFO); logger.info ("Enter"); // logger.info ("Set the log file format..."); // log = org.apache.log4j.Category.getInstance(Application.class.getName()); logger.info ("... done."); logger.debug ("Exit"); logger = org.apache.log4j.Logger.getLogger (CmdExecTester.class); } /** * */ public static String check (String title, StringBuffer source, String model) { String result; if (source.indexOf (model) == -1) { result = String.format ("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model; } else { result = String.format ("%-40s [ OK ] ", title); } // return (result); } /** * */ public static String testCaller (String pathInfo, String prefix) { String result; result = "[" + pathInfo + "]=>[" + ServletDispatcher.pathInfoToClassName(pathInfo, prefix) + "]"; // return(result); } /** * */ public static void test1() { try { System.out.println("Launch ..."); //String command = "/bin/sort -r /etc/passwd"; String[] command = {"/bin/sort", "-r", "/etc/passwd"}; CmdExec cmd = new CmdExec (command, StreamGobbler.BUFFER, StreamGobbler.BUFFER); System.out.println("exitVal=[" + cmd.getExitValue() + "]"); System.out.println("out=[" + cmd.getOutStream() + "]"); System.out.println("err=[" + cmd.getErrStream() + "]"); } catch (Exception exception) { exception.printStackTrace(); logger.info("ERRRO=" + exception); } } /** * */ public static void main(String[] args) { System.out.println("Automatic test action for CmdExec!"); Matcher m = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher("# owner: cpm"); m.matches(); //System.out.println("owner=[" + m.matches() + "]"); System.out.println("owner=[" + m.groupCount() + "]"); System.out.println("owner=[" + m.group(1) + "]"); //test1(); } }