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?

1
  • How do you prepare the CommandLine? Commented May 27, 2010 at 19:24

1 Answer 1

1

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\"");
Sign up to request clarification or add additional context in comments.

2 Comments

So what happens if you go through addArgument methods instead?
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 :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.