1

I want to execute a program (System.getenv("appdata") + "ffmpeg"). I also want to be able get a process or something that could get me the consle output. I have tried "cmd /C " + System.getenv("appdata") + "ffmpeg" before and it didn't seem to work. Any help is appreciated!

Here is some code:

Process p = exec(testFFMpeg);
    int ex = -1;
    try {
        ex = p.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
        CrashHandler.reportCrash("FFMpeg", "Unable to test FFMpeg", "start up with more permissions");
    }

    if(ex == 0){
        System.out.println("Normal execution, exit value: " + ex);
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = null;

        do{
            try {
                line = br.readLine();
                System.out.println(line);
            } catch (IOException e) {
                e.printStackTrace();
                CrashHandler.reportCrash("FFMpeg", "Unable to test FFMpeg", "start up with more permissions");
            }
        }while(line != null);
    }else{
        System.out.println("Execution exit value: " + ex);
    }
}

private static Process exec(String[] cmd){
    try {
        return Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
        e.printStackTrace();
        CrashHandler.reportCrash("FFMpeg", "Unable to test FFMpeg", "start up with more permissions");
    }

The exact location of the file is: `System.getenv("appdata") + "\VinVid\" + "ffmpeg.exe".

4
  • Please look at docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html Commented Oct 6, 2013 at 3:16
  • One thing is that how would I get the output instead of saving to a file. Commented Oct 6, 2013 at 3:28
  • What output you talking about? Commented Oct 6, 2013 at 3:30
  • I mean the consle log Commented Oct 6, 2013 at 3:39

3 Answers 3

1

I figured it out. The output was going to the error stream, not the inputStream.

Sign up to request clarification or add additional context in comments.

Comments

0

You are missing path separator, try this

System.getenv("appdata") + "\\ffmpeg"

2 Comments

can you tell us what error you are getting? Did you add the extension .exe to ffmpeg?
I tried Aneesh's answer but added p.waitFor(); right after creating the BufferedReader and it simply says nothing.
0

In your code change this line line = br.readLine(); to line += br.readLine(); This is how you run a windows process in java. I don't know what output you want. If your asking to print the output of the process you ran, this code helps :

String line;
String pidInfo ="";

Process p =Runtime.getRuntime().exec(System.getenv("appdata") +"ffmpeg.exe");

BufferedReader input =  new BufferedReader(new InputStreamReader(p.getInputStream()));

while ((line = input.readLine()) != null) {
    pidInfo+=line; 
}

input.close();

System.out.println(pidInfo);

4 Comments

There is simply no output
Maybe your process doesn't give any outputs. Replace your cmd with this System.getenv("windir") +"\\system32\\"+"tasklist.exe" and try to see if any output comes
it just stops the app and says nothing same with System.getenv("windir") +"\\system32\\"+"cmd.exe" If I run ffmpeg from cmd it throws out a bunch of output
I'll try using apache commons exec

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.