我想执行一个程序(System.getenv("appdata") + "ffmpeg"
)。我还希望能够获得一个流程或可以让我获得控制台输出的东西。我之前尝试过“cmd /C”+ System.getenv("appdata") + "ffmpeg"
,但似乎没有用。任何帮助表示赞赏!
这是一些代码:
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");
}
该文件的确切位置是:`System.getenv("appdata") + "\VinVid\" + "ffmpeg.exe"。