Original Post
🔒 Locked
[java] [java] Executing system calls? (like copy, del, etc.)
Advertisement
Why don't you use java.io.File.delete ?
i'm not really trying to delete a file, i only used "del myFile.txt" as an example...
i'm trying to call ffmpeg (video conversion) executable file. I can call it on command/DOS prompt, but don't know how in java.
i've tried this:
but I get this:
i'm trying to call ffmpeg (video conversion) executable file. I can call it on command/DOS prompt, but don't know how in java.
i've tried this:
private void runFFMPEG(String aSrcVideo) { //String[] cmd = {"cmd /c ffmpeg -i " + aSrcVideo + " -ar 11025 -ab 32 -f flv -s 450*340 " + aSrcVideo + ".flv"}; String cmd = "ffmpeg -i video.flv -ar 11025 -ab 32 -f flv -s 450*340 video_converted.flv"; Process p = null; try { p = Runtime.getRuntime().exec(cmd); p.waitFor(); BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream())); String line=null; while((line=in.readLine() )!=null) { System.out.println(line); } } catch( Exception e) { System.out.println("hello:" + e); } }but I get this:
File input error
I guess your command works well on the command line shell?! (input: aSrcVideo; output: aSrcVideo.flv)
just an idea, which is probably wrong..
but could it be that the working directory doesn't match with the local path to myFile.txt or aSrcVideo.flv ?
try using an absolut path or check wth System.getProperty("user.dir");
Anyway, I would recommend you to use the ProcessBuilder class, since it offers a bit more control.
just an idea, which is probably wrong..
but could it be that the working directory doesn't match with the local path to myFile.txt or aSrcVideo.flv ?
try using an absolut path or check wth System.getProperty("user.dir");
Anyway, I would recommend you to use the ProcessBuilder class, since it offers a bit more control.
Runtime.exec() will start a new process. To start a process, there has to be some executable file on the disk that can be loaded.
Many commands you can enter in the shell are not an executable, but a function that is recognized by the shell itself. One of those functions is del. If you want to delete a file this way, you have to start the shell (cmd.exe) passing the command along with the other parameters.
Running ffmpeg via Runtime.exec() should be fine, since ffmpeg.exe is an executable file. You may want to specify the complete path to make it work.
Many commands you can enter in the shell are not an executable, but a function that is recognized by the shell itself. One of those functions is del. If you want to delete a file this way, you have to start the shell (cmd.exe) passing the command along with the other parameters.
Running ffmpeg via Runtime.exec() should be fine, since ffmpeg.exe is an executable file. You may want to specify the complete path to make it work.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement