public class Test{ public static void main(String[] args) {try{ String shellString = "lame -b 16 /java/5/a.wav"; String[] cmd = new String[]{"sh","-c",shellString}; Process process = Runtime.getRuntime().exec(cmd); //Process process=Runtime.getRuntime().exec("lame -b 16 /java/5/a.wav"); // lame 你的.wav文件,简易版
process.waitFor(); //阻塞,直到上述命令执行完,一定要在文件close()关闭前面
process.getOutputStream().close();
process.getInputStream().close();
process.getErrorStream().close();
}catch (Throwable e){ } } }
解决java使用Runtime.exec执行linux命令不成功问题
关键问题在于 waitFor( ) ; 关于更多解释 , 请看 http://lelglin.iteye.com/blog/1487351
原文地址:https://www.cnblogs.com/wtcl/p/8207134.html
时间: 2024-10-12 21:32:07