1

I'm writing an app to help myself using ffmpeg, and i got it to work, but the cmd.exe runs in the background. Here is how I call it from java code.

String[] command = new String[] {"cmd.exe", "/c",  "ffmpeg ...etc"};
System.out.println(command[2]);
Process p = Runtime.getRuntime().exec(command);

All info that i found was about running commands IN background, but I need the completely opposite thing. How can I do this?

1 Answers1

0

From what I understand, you're asking how to actually start FFMPEG, as if you opened Command Prompt, and executed the command yourself.

If this is the case, on windows, command prompt has a command for starting an executable as its own process. Aptly named 'start'

Try doing this:

String[] command = new String[] {"start", "C:\Windows\System32\calc.exe"};
Process p = Runtime.getRuntime().exec(command);

A simple explanation of whats happening differently is:

When using

  String[] command = new String[] {"cmd.exe", "/c", "C:\Windows\System32\calc.exe"};

Java will create a new child process of java.exe itself to execute your command, which starts ffmpeg's (Or calculator in this example) command in this child process.

Otherwise using

  String[] command = new String[] {"start", "C:\Windows\System32\calc.exe"};

Will start ffmpeg (or once again calculator here), entirely in its own process as if launched from explorer.exe

EDIT:

I don't have the ability to test this at the moment as my windows computer is not functional. It is possible that you may need to prefix the start command itself with cmd.exe as follows:

  String[] command = new String[] {"cmd.exe", "/c", "start", "C:\Windows\System32\calc.exe"};

BUT to my knowledge either way should work.

Edit2: made explanation more explanatory.

Nackloose
  • 34
  • 3