FileDocCategorySizeDatePackage
ExecAndPrint.javaAPI DocExample1492Mon Apr 30 12:07:10 BST 2001com.darwinsys.util

ExecAndPrint

public class ExecAndPrint extends Object
ExecAndPrint runs a program using Runtime.exec(), read the program's output, and returns its exit status.

Fields Summary
protected static Runtime
r
Need a Runtime object for any of these methods
Constructors Summary
Methods Summary
public static intrun(java.lang.String cmd)
Run the command given as a String, printing its output to System.out


	             
	        
		return run(cmd, new OutputStreamWriter(System.out));
	
public static intrun(java.lang.String cmd, java.io.Writer out)
Run the command given as a String, print its output to "out"

 

		String line;
		
		Process p = r.exec(cmd);

		FileIO.copyFile(new InputStreamReader(p.getInputStream()), out, true);
		try {
			p.waitFor();	// wait for process to complete
		} catch (InterruptedException e) {
			return -1;
		}
		return p.exitValue();
	
public static intrun(java.lang.String[] cmd)
Run the command given as a String[], print its output to System.out

 
		return run(cmd, new OutputStreamWriter(System.out));
	
public static intrun(java.lang.String[] cmd, java.io.Writer out)
Run the command given as a String[], print its output to "out"

 

		String line;
		
		Process p = r.exec(cmd);

		FileIO.copyFile(new InputStreamReader(p.getInputStream()), out, true);

		try {
			p.waitFor();	// wait for process to complete
		} catch (InterruptedException e) {
			return -1;
		}
		return p.exitValue();