Executing command line tool from java varies from command line?
My question is regarding the org.apache.commons.exec.DefaultExecutor.execute(CommandLine command) method in apache commons.
This is the codebit for executing ffmpeg:
command = FFMPEG_DIR + "ffmpeg -i \"" + file.getAbsolutePath() + "\"";
DefaultExecutor executor = new DefaultExecutor();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(baos);
executor.setStreamHandler(streamHandle开发者_运维问答r);
CommandLine commandLine = CommandLine.parse(command);
executor.execute(commandLine);
When I execute a command line tool e.c. ffmpeg from Java like this:
/path_to_ffmpeg/ffmpeg -i "/My Media/Video/Day2/VIDEO.MOV"
The result of ffmpeg is that it can not find the file specified for input
"/My Media/Video/Day2/VIDEO.MOV": No such file or directory
If I execute the command in my console the exact same way it works without any problems. Renaming the "My Media" Folder to "MyMedia" fixes the problem from the Java side, but for me that is not a usable solution.
How can I fix this without having to restrict spaces from the input path?
The examples at http://commons.apache.org/exec/tutorial.html suggest that you do something like:
DefaultExecutor de = new DefaultExecutor();
de.execute(CommandLine.parse("/path_to_ffmpeg/ffmpeg -i \"/My Media/Video/Day2/VIDEO.MOV\"");
精彩评论