Example usage for java.lang System setOut

List of usage examples for java.lang System setOut

Introduction

In this page you can find the example usage for java.lang System setOut.

Prototype

public static void setOut(PrintStream out) 

Source Link

Document

Reassigns the "standard" output stream.

Usage

From source file:net.lightbody.bmp.proxy.jetty.jetty.win32.Service.java

public static void main(String[] arg) {
    String opt;/*www.  java2 s . c  o  m*/
    opt = System.getProperty("SERVICE_OUT");
    if (opt != null) {
        try {
            PrintStream stdout = new PrintStream(new FileOutputStream(opt));
            System.setOut(stdout);
        } catch (Exception e) {
            log.warn(LogSupport.EXCEPTION, e);
        }
    }

    opt = System.getProperty("SERVICE_ERR");
    if (opt != null) {
        try {
            PrintStream stderr = new PrintStream(new FileOutputStream(opt));
            System.setErr(stderr);
        } catch (Exception e) {
            log.warn(LogSupport.EXCEPTION, e);
        }
    }

    if (arg.length == 0)
        arg = new String[] { "etc/jetty.xml" };

    try {
        _configs = new Vector();
        for (int i = 0; i < arg.length; i++)
            _configs.add(arg[i]);
        createAll();
        startAll();
    } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
    }
}

From source file:org.opens.tanaguru.cli.Tanaguru.java

public static void main(String[] args) {
    if (args == null) {
        return;// w w  w  .j  a  v  a 2s. c  o  m
    }
    TANAGURU_HOME = System.getenv("TANAGURU_PATH");
    CommandLineParser clp = new BasicParser();
    try {
        CommandLine cl = clp.parse(OPTIONS, args);
        if (cl.hasOption("h")) {
            printUsage();
            return;
        }
        if (cl.hasOption("f")) {
            String ffPath = cl.getOptionValue("f");
            if (isValidPath(ffPath, "f", false)) {
                System.setProperty("webdriver.firefox.bin", ffPath);
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("r")) {
            String ref = cl.getOptionValue("r");
            if (isValidReferential(ref)) {
                REF = ref;
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("l")) {
            String level = cl.getOptionValue("l");
            if (isValidLevel(level)) {
                LEVEL = level;
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("o")) {
            String outputDir = cl.getOptionValue("o");
            if (isValidPath(outputDir, "o", true)) {
                try {
                    System.setOut(new PrintStream(outputDir));
                } catch (FileNotFoundException ex) {
                    printUsage();
                    return;
                }
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("t")) {
            String auditType = cl.getOptionValue("t");
            if (!isValidAuditType(auditType)) {
                printUsage();
                return;
            } else {
                AUDIT_TYPE = auditType;
            }
        }
        if (AUDIT_TYPE.equalsIgnoreCase(PAGE_AUDIT)) {
            if (!isValidPageUrl(cl)) {
                printUsage();
            } else {
                new Tanaguru().runAuditOnline(cl.getArgs(), TANAGURU_HOME, REF, LEVEL);
            }
        } else if (AUDIT_TYPE.equalsIgnoreCase(SCENARIO_AUDIT)) {
            if (!isValidScenarioPath(cl)) {
                printUsage();
            } else {
                new Tanaguru().runAuditScenario(cl.getArgs()[0], TANAGURU_HOME, REF, LEVEL);
            }
        } else if (AUDIT_TYPE.equalsIgnoreCase(FILE_AUDIT)) {
            if (!isValidFilePath(cl)) {
                printUsage();
            } else {
                new Tanaguru().runAuditUpload(cl.getArgs(), TANAGURU_HOME, REF, LEVEL);
            }
        } else if (AUDIT_TYPE.equalsIgnoreCase(SITE_AUDIT)) {
            if (!isValidSiteUrl(cl)) {
                printUsage();
            } else {
                System.out.println("Functionnality is not working on cli interface");
                printUsage();
            }
        }
    } catch (ParseException ex) {
        java.util.logging.Logger.getLogger(Tanaguru.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.asqatasun.runner.Asqatasun.java

public static void main(String[] args) {
    if (args == null) {
        return;/*from   www  . j a  v a2  s .c  om*/
    }
    ASQATASUN_HOME = System.getenv("ASQATASUN_PATH");
    CommandLineParser clp = new BasicParser();
    try {
        CommandLine cl = clp.parse(OPTIONS, args);
        if (cl.hasOption("h")) {
            printUsage();
            return;
        }
        if (cl.hasOption("f")) {
            String ffPath = cl.getOptionValue("f");
            if (isValidPath(ffPath, "f", false)) {
                System.setProperty("webdriver.firefox.bin", ffPath);
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("d")) {
            String display = cl.getOptionValue("d");
            if (isValidDisplay(display, "d")) {
                System.setProperty("display", ":" + display);
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("r")) {
            String ref = cl.getOptionValue("r");
            if (isValidReferential(ref)) {
                REF = ref;
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("l")) {
            String level = cl.getOptionValue("l");
            if (isValidLevel(level)) {
                LEVEL = level;
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("o")) {
            String outputDir = cl.getOptionValue("o");
            if (isValidPath(outputDir, "o", true)) {
                try {
                    System.setOut(new PrintStream(outputDir));
                } catch (FileNotFoundException ex) {
                    printUsage();
                    return;
                }
            } else {
                printUsage();
                return;
            }
        }
        if (cl.hasOption("t")) {
            String auditType = cl.getOptionValue("t");
            if (!isValidAuditType(auditType)) {
                printUsage();
                return;
            } else {
                AUDIT_TYPE = auditType;
            }
        }
        if (cl.hasOption("x")) {
            String xmxValue = cl.getOptionValue("x");
            if (!isValidXmxValue(xmxValue)) {
                printUsage();
                return;
            }
        }
        if (AUDIT_TYPE.equalsIgnoreCase(PAGE_AUDIT)) {
            if (!isValidPageUrl(cl)) {
                printUsage();
            } else {
                new Asqatasun().runAuditOnline(cl.getArgs(), ASQATASUN_HOME, REF, LEVEL);
            }
        } else if (AUDIT_TYPE.equalsIgnoreCase(SCENARIO_AUDIT)) {
            if (!isValidScenarioPath(cl)) {
                printUsage();
            } else {
                new Asqatasun().runAuditScenario(cl.getArgs()[0], ASQATASUN_HOME, REF, LEVEL);
            }
        } else if (AUDIT_TYPE.equalsIgnoreCase(FILE_AUDIT)) {
            if (!isValidFilePath(cl)) {
                printUsage();
            } else {
                new Asqatasun().runAuditUpload(cl.getArgs(), ASQATASUN_HOME, REF, LEVEL);
            }
        } else if (AUDIT_TYPE.equalsIgnoreCase(SITE_AUDIT)) {
            if (!isValidSiteUrl(cl)) {
                printUsage();
            } else {
                System.out.println("Functionnality is not working on cli interface");
                printUsage();
            }
        }
    } catch (ParseException ex) {
        java.util.logging.Logger.getLogger(Asqatasun.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:ch.epfl.leb.sass.commandline.CommandLineInterface.java

/**
 * Shows help, launches the interpreter and executes scripts according to input args.
 * @param args input arguments//from ww  w.  j av a 2  s .  c o  m
 */
public static void main(String args[]) {
    // parse input arguments
    CommandLineParser parser = new DefaultParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
    } catch (ParseException ex) {
        System.err.println("Parsing of arguments failed. Reason: " + ex.getMessage());
        System.err.println("Use -help for usage.");
        System.exit(1);
    }

    // decide how do we make the interpreter available based on options
    Interpreter interpreter = null;
    // show help and exit
    if (line.hasOption("help")) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("java -jar <jar-name>", options, true);
        System.exit(0);
        // launch interpreter inside current terminal
    } else if (line.hasOption("interpreter")) {
        // assign in, out and err streams to the interpreter
        interpreter = new Interpreter(new InputStreamReader(System.in), System.out, System.err, true);
        interpreter.setShowResults(true);
        // if a script was given, execute it before giving access to user
        if (line.hasOption("script")) {
            try {
                interpreter.source(line.getOptionValue("script"));
            } catch (IOException ex) {
                Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE,
                        "IOException while executing shell script.", ex);
            } catch (EvalError ex) {
                Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE,
                        "EvalError while executing shell script.", ex);
            }
        }
        // give access to user
        new Thread(interpreter).start();
        // only execute script and exit
    } else if (line.hasOption("script")) {
        interpreter = new Interpreter();
        try {
            interpreter.source(line.getOptionValue("script"));
            System.exit(0);
        } catch (IOException ex) {
            Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE,
                    "IOException while executing shell script.", ex);
            System.exit(1);
        } catch (EvalError ex) {
            Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE,
                    "EvalError while executing shell script.", ex);
            System.exit(1);
        }

        // Launches the RPC server with the model contained in the file whose
        // filename was passed by argument.
    } else if (line.hasOption("rpc_server")) {

        IJPluginModel model = new IJPluginModel();
        File file = new File(line.getOptionValue("rpc_server"));
        try {
            FileInputStream stream = new FileInputStream(file);
            model = IJPluginModel.read(stream);
        } catch (FileNotFoundException ex) {
            System.out.println("Error: " + file.getName() + " not found.");
            System.exit(1);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // Check whether a port number was specified.
        if (line.hasOption("port")) {
            try {
                port = Integer.valueOf(line.getOptionValue("port"));
                System.out.println("Using port: " + String.valueOf(port));
            } catch (java.lang.NumberFormatException ex) {
                System.out.println("Error: the port number argument is not a number.");
                System.exit(1);
            }
        } else {
            System.out.println("No port number provided. Using default port: " + String.valueOf(port));
        }

        RPCServer server = new RPCServer(model, port);

        System.out.println("Starting RPC server...");
        server.serve();

    } else if (line.hasOption("port") & !line.hasOption("rpc_server")) {
        System.out.println("Error: Port number provided without requesting the RPC server. Exiting...");
        System.exit(1);

        // if System.console() returns null, it means we were launched by
        // double-clicking the .jar, so launch own BeanShellConsole
        // if System.console() returns null, it means we were launched by
        // double-clicking the .jar, so launch own ConsoleFrame
    } else if (System.console() == null) {
        BeanShellConsole cframe = new BeanShellConsole("SASS BeanShell Prompt");
        interpreter = cframe.getInterpreter();
        cframe.setVisible(true);
        System.setOut(cframe.getInterpreter().getOut());
        System.setErr(cframe.getInterpreter().getErr());
        new Thread(cframe.getInterpreter()).start();
        // otherwise, show help
    } else {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("java -jar <jar-name>", options, true);
        System.exit(0);
    }

    if (interpreter != null) {
        printWelcomeText(interpreter.getOut());
    }
}

From source file:Main.java

public static void resultToFile(String path) throws FileNotFoundException {
    File file = new File(path);
    PrintStream printStream = new PrintStream(new FileOutputStream(file));
    PrintStream out = printStream;
    System.setOut(out);
}

From source file:com.clustercontrol.util.StdOutErrLog.java

/**
 * ?log4j??<br/>//from   www.j  a  v a2  s.c o m
 */
public static void initialize() {
    System.setOut(new PrintStream(new LoggerStream(log)));
    System.setErr(new PrintStream(new LoggerStream(log)));
}

From source file:Main.java

public Main() {
    setSize(300, 300);/*from   ww  w. j  av  a 2 s.c  om*/
    add("Center", new JScrollPane(aTextArea));
    setVisible(true);

    System.setOut(aPrintStream); // catches System.out messages
    System.setErr(aPrintStream); // catches error messages
}

From source file:fi.jumi.core.stdout.SystemOutErrTest.java

@After
public void restoreStdoutStderr() {
    System.setOut(originalStdout);
    System.setErr(originalStderr);
}

From source file:StdErrOutWindows.java

public StdErrOutWindows() {
    JScrollPane pain = new JScrollPane(outArea);
    JFrame outFrame = new JFrame("out");
    outFrame.getContentPane().add(pain);
    outFrame.setVisible(true);//from w  w  w.  ja va2 s .  c  o  m

    pain = new JScrollPane(errArea);
    JFrame errFrame = new JFrame("err");
    errFrame.getContentPane().add(pain);
    errFrame.setLocation(errFrame.getLocation().x + 20, errFrame.getLocation().y + 20);
    errFrame.setVisible(true);

    System.setOut(new PrintStream(new JTextAreaOutputStream(outArea)));
    System.setErr(new PrintStream(new JTextAreaOutputStream(errArea)));
}

From source file:edu.stanford.muse.email.VerifyEmailSetup.java

public static Pair<Boolean, String> run() {
    PrintStream savedOut = System.out;
    InputStream savedIn = System.in;

    try {// w ww  . j  a  va 2s . c om
        // Get a Properties object
        Properties props = System.getProperties();

        // Get a Session object
        Session session = Session.getInstance(props, null);
        session.setDebug(true);
        String filename = System.getProperty("java.io.tmpdir") + File.separatorChar + "verifyEmailSetup";
        PrintStream ps = new PrintStream(new FileOutputStream(filename));
        System.setOut(ps);
        System.setErr(ps);

        // Get a Store object
        Store store = null;
        store = session.getStore("imaps");
        store.connect("imap.gmail.com", 993, "checkmuse", ""); // not the real password. unfortunately, the checkmuse a/c will get blocked by google.
        //           Folder folder = store.getFolder("[Gmail]/Sent Mail");
        //           int totalMessages = folder.getMessageCount();
        // System.err.println (totalMessages + " messages!");
        ps.close();
        String contents = Util.getFileContents(filename);
        System.out.println(contents);
        return new Pair<Boolean, String>(Boolean.TRUE, contents);
    } catch (AuthenticationFailedException e) {
        /* its ok if auth failed. we only want to check if IMAPS network route is blocked.
         when network is blocked, we'll get something like
        javax.mail.MessagingException: No route to host; 
        nested exception is: 
        java.net.NoRouteToHostException: No route to host 
        ...
        */
        log.info("Verification succeeded: " + Util.stackTrace(e));
        return new Pair<Boolean, String>(Boolean.TRUE, "");
    } catch (Exception e) {
        log.warn("Verification failed: " + Util.stackTrace(e));
        return new Pair<Boolean, String>(Boolean.FALSE, e.toString()); // stack track reveals too much about our code... Util.stackTrace(e));         
    } finally {
        System.setOut(savedOut);
        System.setIn(savedIn);
    }
}