views:

50

answers:

2

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(streamHandler);

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?

A: 

You need to escape space character like it:

"/My\ Media/Video/Day2/VIDEO.MOV"
Laurent
This works if you are using the osx command line, but not from Java
itkevin
+1  A: 

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\"");
aioobe
I do parse the command before executing. Same issue
itkevin
So what happens if you go through `addArgument` methods instead?
aioobe
Same result. When I change the working directory to "/My Media/Video/Day2" it works for files without whitespaces?!? I have spent all day on this and I can't figure it out somehow :(
itkevin