打开ffplay&使用ProcessBuilder执行命令不起作用

时间:2015-07-27 18:31:04

标签: java cmd ffmpeg

我尝试使用ProcessBuilder打开ffplay.exe并将命令执行到ffplay。然而,它是不成功的。我怎么能这样做?

代码:

ProcessBuilder pb = new ProcessBuilder();

pb.command("C:\\Windows\\System32\\cmd.exe", "/c",
"C:\\ffmpeg\\bin\\ffplay.exe", "tcp://192.168.1.1:5555"); 

pb.start();

1 个答案:

答案 0 :(得分:0)

尝试使用Runtime.getRuntime().exec()并执行以下操作: -

String[] command = {"ffplay.exe", "tcp://192.168.1.1:5555"}; // add in String array in sequence, the commands to execute
Process process = Runtime.getRuntime().exec(String[] options, null, new File("C:\\ffmpeg\\bin"));
int returnVal = process.waitFor(); // should return 0 for correct execution
try {
            final BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                System.out.println(line); //check for the inputstream & see the output here
            }
            reader.close();
        } catch (final Exception e) {
            e.printStackTrace();
        }