List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:org.apache.hadoop.mpich.MpichContainerWrapper.java
public void run() { try {/* w w w . jav a 2 s. c om*/ clientSock = new Socket(ioServer, ioServerPort); System.setOut(new PrintStream(clientSock.getOutputStream(), true)); System.setErr(new PrintStream(clientSock.getOutputStream(), true)); String hostName = InetAddress.getLocalHost().getHostName(); System.out.println("Starting process " + executable + " on " + hostName); List<String> commands = new ArrayList<String>(); commands.add(executable); if (appArgs != null && appArgs.length > 0) { commands.addAll(Arrays.asList(appArgs)); } ProcessBuilder processBuilder = new ProcessBuilder(commands); processBuilder.redirectErrorStream(true); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); Map<String, String> evns = processBuilder.environment(); evns.put("PMI_RANK", rank); evns.put("PMI_SIZE", np); evns.put("PMI_ID", pmiid); evns.put("PMI_PORT", pmiServer + ":" + pmiServerPort); if (this.isSpawn) { evns.put("PMI_SPAWNED", "1"); } LOG.info("Starting process:"); for (String cmd : commands) { LOG.info(cmd + "\n"); } Process process = processBuilder.start(); System.out.println("Process exit with value " + process.waitFor()); System.out.println("EXIT");//Stopping IOThread clientSock.close(); } catch (UnknownHostException exp) { System.err.println("Unknown Host Exception, Host not found"); exp.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.fau.cs.osr.hddiff.perfsuite.RunFcDiff.java
private String runFcDiff(File fileA, File fileB, File fileDiff) throws IOException { PrintStream oldOut = System.out; PrintStream oldErr = System.err; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { try {//from w w w . j av a 2 s. c om try (PrintStream ps = new PrintStream(baos)) { System.setOut(ps); System.setErr(ps); fc.xml.diff.Diff.main(new String[] { fileA.getAbsolutePath(), fileB.getAbsolutePath(), fileDiff.getAbsolutePath() }); } finally { System.setOut(oldOut); System.setErr(oldErr); } } catch (Exception e) { throw new FcDiffException(new String(baos.toByteArray()), e); } return new String(baos.toByteArray()); } }
From source file:org.apache.taverna.scufl2.wfdesc.TestConvertToWfdesc.java
private void help(String argName) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream outBuf = new PrintStream(out); ByteArrayOutputStream err = new ByteArrayOutputStream(); PrintStream errBuf = new PrintStream(err); try {//www . ja v a 2 s .com System.setOut(outBuf); System.setErr(errBuf); ConvertToWfdesc.main(new String[] { argName }); } finally { restoreStd(); } out.flush(); out.close(); err.flush(); err.close(); assertEquals(0, err.size()); String help = out.toString("utf-8"); // System.out.println(help); assertTrue(help.contains("scufl2-to-wfdesc")); assertTrue(help.contains("\nIf no arguments are given")); }
From source file:org.apache.rocketmq.tools.command.message.ConsumeMessageCommandTest.java
@Test public void testExecuteDefault() throws SubCommandException { PrintStream out = System.out; ByteArrayOutputStream bos = new ByteArrayOutputStream(); System.setOut(new PrintStream(bos)); Options options = ServerUtil.buildCommandlineOptions(new Options()); String[] subargs = new String[] { "-t mytopic", "-n localhost:9876" }; CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + consumeMessageCommand.commandName(), subargs, consumeMessageCommand.buildCommandlineOptions(options), new PosixParser()); consumeMessageCommand.execute(commandLine, options, null); System.setOut(out);/* ww w. jav a2 s . c om*/ String s = new String(bos.toByteArray()); Assert.assertTrue(s.contains("Consume ok")); }
From source file:org.arquillian.spacelift.process.impl.ProcessNameTest.java
@Test public void outputDefaultPrefix() throws UnsupportedEncodingException { // run only on linux Assume.assumeThat(SystemUtils.IS_OS_LINUX, is(true)); final ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); System.setOut(new PrintStream(errorOutput)); exception = ExpectedException.none(); try {/*from www .j ava2 s .co m*/ exception.expectMessage(containsString("java -bar -baz")); Tasks.prepare(CommandTool.class).programName("java").parameters("-bar", "-baz") .interaction(new ProcessInteractionBuilder().when(".*").printToOut()).execute().await(); } catch (ExecutionException e) { // ignore } String output = errorOutput.toString(Charset.defaultCharset().name()); Assert.assertThat(output, startsWith("(java):Unrecognized option: -bar")); }
From source file:org.apache.hadoop.tools.TestHadoopArchives.java
private static List<String> lsr(final FsShell shell, String dir) throws Exception { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(bytes); final PrintStream oldOut = System.out; final PrintStream oldErr = System.err; System.setOut(out); System.setErr(out);/*w w w .ja v a2 s . c om*/ final String results; try { assertEquals(0, shell.run(new String[] { "-lsr", dir })); results = bytes.toString(); } finally { IOUtils.closeStream(out); System.setOut(oldOut); System.setErr(oldErr); } final String dirname = dir.substring(dir.lastIndexOf(Path.SEPARATOR)); final List<String> paths = new ArrayList<String>(); for (StringTokenizer t = new StringTokenizer(results, "\n"); t.hasMoreTokens();) { final String s = t.nextToken(); final int i = s.indexOf(dirname); if (i >= 0) { paths.add(s.substring(i + dirname.length())); } } Collections.sort(paths); return paths; }
From source file:nl.knaw.huygens.alexandria.dropwizard.cli.CommandIntegrationTest.java
@Before public void setUp() throws IOException { setupWorkDir();//from ww w . j a va2 s.co m // Setup necessary mock final JarLocation location = mock(JarLocation.class); when(location.getVersion()).thenReturn(Optional.of("1.0.0")); when(location.toString()).thenReturn("alexandria-app.jar"); // Add commands you want to test ServerApplication serverApplication = new ServerApplication(); final Bootstrap<ServerConfiguration> bootstrap = new Bootstrap<>(serverApplication); final AppInfo appInfo = new AppInfo().setVersion("$version$").setBuildDate("$buildDate$"); serverApplication.addCommands(bootstrap, appInfo); // Redirect stdout and stderr to our byte streams System.setOut(new PrintStream(stdOut)); System.setErr(new PrintStream(stdErr)); // Build what'll run the command and interpret arguments cli = new Cli(location, bootstrap, stdOut, stdErr); }
From source file:brooklyn.util.stream.ThreadLocalPrintStream.java
/** installs a thread local print stream to System.out if one is not already set; * caller may then #capture and #captureTee on it. * @return the ThreadLocalPrintStream which System.out is using */ public synchronized static ThreadLocalPrintStream stdout() { PrintStream oldOut = System.out; if (oldOut instanceof ThreadLocalPrintStream) return (ThreadLocalPrintStream) oldOut; ThreadLocalPrintStream newOut = new ThreadLocalPrintStream(System.out); System.setOut(newOut); return newOut; }
From source file:ape_test.CLITest.java
public void testHelpWithVerbose() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps); String[] arg = new String[2]; arg[0] = "h"; arg[1] = "v"; Main.main(arg);/*from w w w .j av a 2 s . co m*/ System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:ai.serotonin.backup.Base.java
void execute() { final File processLock = new File(".lock" + suffix); if (processLock.exists()) { sendEmail("Backup/restore failure!", "Another process is already running. Aborting new run."); return;//w ww .ja v a 2 s . c o m } String emailSubject = null; try (MulticastOutputStream mos = new MulticastOutputStream(); final FileOutputStream logOut = new FileOutputStream("log" + suffix + ".txt", true); final PrintStream out = new PrintStream(mos)) { lock(processLock); // Redirect output to file and memory log. memoryLog = new ByteArrayOutputStream(); // mos.setExceptionHandler(new IOExceptionHandler() { // @Override // public void ioException(OutputStream stream, IOException e) { // e.printStackTrace(s); // } // }); mos.addStream(logOut); mos.addStream(memoryLog); System.setOut(out); System.setErr(out); executeImpl(); emailSubject = "Backup/restore completion"; } catch (final Exception e) { LOG.error("An error occurred", e); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); // TODO sw isn't used? emailSubject = "Backup/restore failure!"; } finally { // Send the result email final String content = new String(memoryLog.toByteArray()); sendEmail(emailSubject, content); unlock(processLock); } }