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......"); } }}Reference:
http://hi.baidu.com/litertiger/blog/item/822a7ef049c913d47831aa19.html
http://blog.csdn.net/georgejin/archive/2010/10/13/5937877.aspx
http://hi.baidu.com/zhangtianshun/blog/item/ae632246b572b40e6a63e579.html
转自:http://www.liaoqiqi.com/blog/2011/java-call-shell-command-redirection-pipeline-problems/