我试图运行cmd命令。一切正常,但没有输出。我不明白为什么。 更新的代码cmd命令不能在java程序中运行
import java.io.*;
import java.util.*;
class CmdTest {
public static void main(String[] args) throws Exception {
String command= "ffmpeg -i D:\\test%d.jpg -vcodec mpeg4 outfile.avi";
Process process;
System.out.println("first stmt");
try
{
process = Runtime.getRuntime().exec(command);
Scanner kb = new Scanner(process.getInputStream());
System.out.println("try block");
} catch (IOException e)
{
e.printStackTrace();
}
System.out.println("last stmt");
}
}
我期待上述cmd命令的执行。编译和执行过程中没有任何问题。但是,命令不执行写入。
你期待什么输出...? –
请更具体 - 什么不按预期工作?应该发生什么? – radar
尝试添加'process.waitFor();'也从错误流中读取。 –