V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
mortonnex
V2EX  ›  问与答

使用 runtime.exec()执行 shell 命令和直接在终端执行得到的结果不一样?

  •  
  •   mortonnex · Jun 25, 2017 · 2260 views
    This topic created in 3240 days ago, the information mentioned may be changed or developed.

    用 java 代码是:

            List<String> command = new ArrayList<String>();
            command.add("ffmpeg");
            command.add("-i");
            command.add("/Users/welcome/Downloads/testVedio/test.mp4");
            command.add("-s");
            command.add("350x240");
            command.add("-y");
            command.add("-threads");
            command.add("4");
            command.add("/Users/welcome/Downloads/testVedio/test/%d.png");
            ProcessBuilder processBuilder = new ProcessBuilder();
            processBuilder.command(command);
            processBuilder.redirectErrorStream(true);
            processBuilder.start();
    

    shell 命令是:

    ffmpeg -i /Users/welcome/Downloads/testVedio/test.mp4 -s 350x240 -y -threads 4 /Users/welcome/Downloads/testVedio/test/%d.png
    

    得出来的效果不一样,直接执行命令是正确的,java 代码执行会少生成很多截图

    1 replies    2017-06-25 23:11:31 +08:00
    SoloCompany
        1
    SoloCompany  
       Jun 25, 2017
    你没有 waitFor

    那么很可能进程刚启动就被杀死了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3008 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 116ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    ♥ Do have faith in what you're doing.