JAVA调用shell命令时重定向、管道时遇到的问题
用java在Linux环境下执行shell命令,可以使用如下方法:
import java.io.IOException;public class JavaShell{ /** * @param args * @throws IOException * @throws InterruptedException */ public static void main(String[] args) throws IOException, InterruptedException { Process p; p = Runtime.getRuntime().exec(new String[]{"sh","-c","md5sum a.c > a.c.md5"}); if(0==p.waitFor()) { System.out.println("Command execute result is OK!"); } else { System.out.println("Command execute result is fail......"); } }}