Ariana Ariana - 1 year ago 85
Java Question

Java execute command line and always replace when it asks [Y/N]

I am calling java.lang.Runtime.exec(...) in my Java program to run a command, say:

ffmpeg -i input.mp4 output.mp4
.

This is simply passed to my function to run:

private static void RunCommand(String command) throws InterruptedException {
try {
// Execute command
Process proc = Runtime.getRuntime().exec(command);
}
}


Everything is OK. But my question is to handle cases when the file already exists, so asks if it should replace it:

File 'output.avi' already exists. Overwrite ? [y/N]


What is the simplest way to ignore it (always assume y and replace)? Maybe through Java in code or FFMPEG command itself?

Answer Source

Add -y as argument:

ffmpeg -y -i input.mp4 output.mp4

According to the documentation:

  • -y Overwrite output files without asking.

  • -n Do not overwrite output files, and exit immediately if a specified output file already exists.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download