java不会执行我的shell脚本

时间:2013-09-08 19:38:06

标签: java android shell

我想执行这个shell脚本:

export.run

cd ./AndroidExport/
ant release

使用这个java代码:

      .....
      Runtime shell = Runtime.getRuntime();
        Process prozess = null;
        String cmd = "sh ./export/android/export.run";
        try {
            prozess = shell.exec(cmd);

        } catch (IOException ioe) {
        }
         BufferedReader in = new BufferedReader(
           new InputStreamReader(prozess.getInputStream()) );
         String line;

   while ((line = in.readLine()) != null) {
     System.out.println(line);
   }
   .....

当我在控制台中执行shell脚本时,它会编译android项目并获得此输出:

Buildfile: /home/myhome/NetBeansProjects/ITGEditor/export/android/AndroidExport   /build.xml

  -set-mode-check:

  -set-release-mode:
   [echo] *************************************************
   [echo] ****  Android Manifest has debuggable=true   ****
   [echo] **** Doing DEBUG packaging with RELEASE keys ****
   [echo] *************************************************

以及更多行,但是当我用java执行它时,它不会编译它而且java控制台只打印第一行:

Buildfile: /home/myhome/NetBeansProjects/ITGEditor/export/android/AndroidExport   /build.xml

问题出在哪里? 谢谢!

1 个答案:

答案 0 :(得分:0)

尝试在shell命令中添加-l选项:

        String cmd = "sh -l ./export/android/export.run";