Java核心代码例程之:ProcessDemo.java
2008-01-05 08:38:26 来源:WEB开发网核心提示:import java.io.*;/** * Demonstrates how to run a PRogram and read it"s output ***/public class ProcessDemo{public static void main(String args[]) throws Ex
import java.io.*;
/**
* Demonstrates how to run a PRogram and read it"s output
***/
public class ProcessDemo
{
public static void main(String args[]) throws Exception
{
Process process = Runtime.getRuntime().exec("ls");
InputStream standardOutput = process.getInputStream(),
standardError = process.getErrorStream();
int c;
System.out.println("
[ Standard Output ]");
while ((c = standardOutput.read()) != -1)
System.out.print((char)c);
System.out.println("
[ Standard Error ]");
while ((c = standardError.read()) != -1)
System.out.print((char)c);
standardOutput.close();
standardError.close();
}
}
更多精彩
赞助商链接