All pastes #161025 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-04 23:00 UTC
rendered paste body
package org.jamescarr.payfuse.fit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class PayFuseTest {

	public class StreamGobbler extends Thread {

		private InputStream is;

		private String type;

		public StreamGobbler(InputStream is, String type) {
			this.type = type;
			this.is = is;
		}

		public void run() {
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(is));
			try {
				System.out.println("Running " + this.type);
				String line = "";
				while ((line = reader.readLine()) != null)
					System.out.println(type + ">" + line);
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		PayFuseTest pf = new PayFuseTest();
		try {
			pf.testInput();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void testInput() throws IOException, InterruptedException {

		String[] command = new String[2];
//		command[0] = "/bin/sh";
		command[0] = "/usr/bin/php";
		command[1] = "-h";
//		command[1] = "/usr/bin/php /home/jamescarr/workspace/Payfuse/src/core/php/cliInput.php";
		Process proc = Runtime.getRuntime().exec(command );

		// any errors?
		StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(),
				"ERROR");

		// any output?
		StreamGobbler outputGobbler = new StreamGobbler(proc.getErrorStream(),
				"OUTPUT");

		errorGobbler.start();
		outputGobbler.start();

		int exitCode = proc.waitFor();
		System.out.println("exit code: " + exitCode);

	}
}