how to execute command line .exe file in java

前端 未结 2 1120
遇见更好的自我
遇见更好的自我 2020-12-08 22:13
  1. i want to convert an avi file to 3gp using java program.
  2. For this i am using \"E.M. Total Video Converter Command Line 2.43\" and the command for it is
2条回答
  •  轮回少年
    2020-12-08 22:46

    You've got all the pieces in your question. It's just a matter of putting it all together.

    Something such as the following should work:

    public class Test {
        public static void main(String[] args) throws Exception {
    
            String[] cmd = { "C:\\E.M. TVCC\\TVCC.exe", "-f E:\\TestVideo\\01.avi", "-o E:\\OutputFiles\\target.3gp" };
            Process p = Runtime.getRuntime().exec(cmd);
            p.waitFor();
        }
    }
    

    That said, hard coding paths like this isn't a good idea, you should read them from somewhere; arguments to your program, a properties file, etc.

提交回复
热议问题