import java.io.*;
import java.util.*;
public class DoRuntime {
public static void main(String args[]) throws IOException { if (args.length <= 0) {
System.err.println("Need command to run");
System.exit(-1);
} Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(args);
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line; System.out.printf("Output of running %s is:",
Arrays.toString(args)); while ((line = br.readLine()) != null) {
System.out.println(line);
} }
} If you run DoRuntime in Solaris like this: java DoRuntime lsYou get output that looks something like this (which depends on the contents of the directory): Output of running ls is:DoRuntime.class
DoRuntime.java
import java.util.*;
public class DoRuntime {
public static void main(String args[]) throws IOException { if (args.length <= 0) {
System.err.println("Need command to run");
System.exit(-1);
} Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(args);
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line; System.out.printf("Output of running %s is:",
Arrays.toString(args)); while ((line = br.readLine()) != null) {
System.out.println(line);
} }
} If you run DoRuntime in Solaris like this: java DoRuntime lsYou get output that looks something like this (which depends on the contents of the directory): Output of running ls is:DoRuntime.class
DoRuntime.java
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货