when I run this command ffmpeg -i "C:\user\test.wmv" >C:\user\test.wmv_info.txt 2>&1 from command prompt it works but when I try to the same from java file by calling the command prompt it executes all right but does not writes to the file.
Any idea why?
my java code is:
public void getInfoThroughCommandLine(String sourceFilePath) {
try {
String infoFile = sourceFilePath+"_info.txt";
String command = "ffmpeg -i \""
+ sourceFilePath +"\" >"+infoFile+" 2>&1";
// Execute the command
Process process = Runtime.getRuntime().exec("cmd.exe /c start " + command);
logger.info("Executing getInfoThroughCommandLine command: " + command);
// Read the response
BufferedReader input = new BufferedReader(new InputStreamReader(
p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(
p.getErrorStream()));
// Parse the input stream
String line = input.readLine();
System.out.println("ffmpeg execution of: " + sourceFilePath);
while (line != null) {
System.out.println("\t***" + line);
line = input.readLine();
}
// Parse the error stream
line = error.readLine();
System.out.println("Error Stream: " + sourceFilePath);
while (line != null) {
//do somthing
}
} catch (Exception e) {
System.err.println(e);
}
}
I assume you’re using
getRuntime().exec()to execute?If so the
Processobject returned by it would be the one giving you access to in/out streams of the command you execute. Just read from it and write your own file.— edit based on discussion via comments —
start in
"cmd.exe /c start " + commandwould start the program in a separate window, and I guess the streams of the process are attached to that window.Try removing it. I.e.