linux下java调用shell和windows下java调用bat

package lunzi.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestExe {

/**
* @param args
*/

public static void main(String[] args) {
try {
// String[] cmd = new String[] { "F:/task/aapt.exe", "l -a
// F:/task/update/10-6-23/apk/4003373.apk >
// F:/task/update/10-6-23/apk/4003373.txt" };
// Process process = Runtime.getRuntime().exec(cmd,null,new
// File("F:/task/"));
String command =
"cmd /c start F:/task/task2010.6.24.bat";
// command ="F:/task/aapt.exe l -a
// F:/task/update/10-6-23/apk/4003373.apk >
// F:/task/update/10-6-23/apk/4003373.txt";

/*
* command = "/home/dingym/aapt d badging
* /home/dingym/YichaMarket.apk";
* System.out.println("------------start-------------");
* Runtime.getRuntime().exec(command);
* System.out.println("------------end---------------");
*/

/*
* BufferedReader r = new BufferedReader(new
* InputStreamReader(process .getErrorStream())); String l = null;
* while ((l = r.readLine()) != null) { System.out.println(l); }
*/


Runtime rt = Runtime.getRuntime();
System.out.println(
"------------start-test-------------");
String str[] = {
"/bin/sh", "-c", "./aapt d badging YichaMarket.apk" };
System.out.println(
"------------end-test---------------");
Process pcs = rt.exec(str);
BufferedReader br = new BufferedReader(new InputStreamReader(pcs
.getInputStream()));
String line = new String();
while ((line = br.readLine()) != null) {
System.out.println(line);
}
try {
pcs.waitFor();
} catch (InterruptedException e) {
System.err.println(
"processes was interrupted");
}
br.close();
int ret = pcs.exitValue();
System.out.println(ret);

} catch (Exception e) {
e.printStackTrace();
}
}

}

lunzi   2011-06-22 21:31:18 评论:1   阅读:1317   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog