解决方案 »

  1.   

    进程在退出前,不仅返回退出码,还有错误信息输出的。你可以把这些错误信息捕捉到,就知道啥问题了:
    StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR"); 
    errorGobbler.start();//  kick  off  stderr
    StreamGobbler 源码:
    import  java.io.BufferedReader;  
    import  java.io.IOException;  
    import  java.io.InputStream;  
    import  java.io.InputStreamReader;  
    import  java.io.OutputStream;  
    import  java.io.PrintWriter;  public class StreamGobbler extends  Thread {
    InputStream is;
    String type;
    OutputStream os; public StreamGobbler(InputStream is, String type) {
    this(is, type, null);
    } public StreamGobbler(InputStream is, String type, OutputStream redirect) {
    this.is = is;
    this.type = type;
    this.os = redirect;
    } @Override
    public void run() {
    PrintWriter pw = null;
    InputStreamReader isr = null;
    BufferedReader br = null;
    try {

    if (os != null)
    pw = new PrintWriter(os); isr = new InputStreamReader(is);
    br = new BufferedReader(isr);
    String line = null;
    while ((line = br.readLine()) != null) {
    if (pw != null)
    pw.println(line);
    //System.out.println(type + ">" + line);
    }
    if (pw != null)
    pw.flush();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    } finally {
    if (pw != null) {
    pw.close();
    }
    if (br != null) {
    try {
    br.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if (isr != null) {
    try {
    isr.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if (os != null) {
    try {
    os.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if (is != null) {
    try {
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }
      

  2.   

    此外,既然 terminal 可以成功执行,启动 shell,然后自定义命令行作为参数传递给 shell 解释器。shell 知道如何将程序员的意图转达给底层。使用 sh -c,将自定义 CMD 行作为其参数,最后使用 java.lang.Runtimeexec(String[] cmdarray),类似于这种:
    String raw2flvCmd = "/usr/local/ffmpeg/bin/ffmpeg -i \"某视频文件下载URL\" -f flv /usr/userfile/ffmpeg/tempfile/1.flv";  
    Runtime.getRuntime().exec(new String[]{"sh","-c",raw2flvCmd}); 
    你按照自己的 CMD,改一下就可以了。