简体   繁体   English

cmd命令未在Java程序中运行

[英]cmd command not running within java program

I am trying to run a cmd command. 我正在尝试运行cmd命令。 Everything works fine but no output. 一切正常,但没有输出。 I don't understand why. 我不明白为什么。 UPDATED CODE 更新的代码

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");
    }
}

I am expecting execution of cmd command mentioned above. 我期望执行上面提到的cmd命令。 Nothing is going wrong during compilation and execution. 在编译和执行期间没有任何问题。 However, command not executing write. 但是,命令不执行写操作。

First, your code should give error because the line Scanner kb = new Scanner(process.getInputStream()); 首先,您的代码应该给出错误,因为行Scanner kb = new Scanner(process.getInputStream()); will not see process. 将看不到进程。 process is defined inside try-catch . processtry-catch内部定义。

Secondly, have you tried ffmpeg -i D:\\\\test%d.jpg -vcodec mpeg4 outfile.avi on command window ? 其次,您是否在command window上尝试过ffmpeg -i D:\\\\test%d.jpg -vcodec mpeg4 outfile.avi If not, try it. 如果没有,请尝试。

Third, instead of running that command try running some easy commands like dir , pwd etc. 第三,不要运行该命令,而是尝试运行一些简单的命令,例如dirpwd等。

Fourth, put some System.out.println("say something") inside the code, then you would be able to see where it fails/stops. 第四,在代码中放入一些System.out.println("say something") ,这样您就可以看到它失败/停止的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM