我在linux环境下调用一个程序,写法如下
try{
Process proc = Runtime.getRuntime().exec(command);
InputStream in= proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line=br.readLine())!=null){
System.out.println(line);
}
}
catch(IOException ex){
ex.printStackTrace();
}
command是一个命令,在控制台执行没有问题的,不过打印输出有一点多,然后按照我的方法调用就会做到一半没有响应的,看了jdk说有些本机平台仅针对标准输入和输出流提供有限的缓冲区大小,如果读写子进程的输出流或输入流迅速出现失败,则可能导致子进程阻塞,甚至产生死锁。 也不知道是不是这个原因,请教高手给以指点。怎么解决。
try{
Process proc = Runtime.getRuntime().exec(command);
InputStream in= proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line=br.readLine())!=null){
System.out.println(line);
}
}
catch(IOException ex){
ex.printStackTrace();
}
command是一个命令,在控制台执行没有问题的,不过打印输出有一点多,然后按照我的方法调用就会做到一半没有响应的,看了jdk说有些本机平台仅针对标准输入和输出流提供有限的缓冲区大小,如果读写子进程的输出流或输入流迅速出现失败,则可能导致子进程阻塞,甚至产生死锁。 也不知道是不是这个原因,请教高手给以指点。怎么解决。
在cmd下正常 runntime未必正常
#!/bin/sh
/root/ffmpeg -i $2 -y -ab 56 -ar 22050 -b 500 -sameq -s 800*600 $3
* 执行cmd命令
*/
private final static String windowsRunCommand(String cmdStr) throws IOException
{
Process p = Runtime.getRuntime().exec(cmdStr);
InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
StringBuffer buffer = new StringBuffer();
for (;;)
{
int c = stdoutStream.read();
if (c == -1) break;
buffer.append((char) c);
}
String outputText = buffer.toString();
stdoutStream.close();
return outputText;
}^_^ 给我分,可以结贴了