File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes calling unix application mplayer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "calling unix application mplayer" Watch "calling unix application mplayer" New topic

calling unix application mplayer

Matt Zollinhofer
Ranch Hand

Joined: Jul 09, 2004
Posts: 33
I thought maybe the thread group would have a little more insight about my problem. I'm trying to write little script that automates two unix (now OS X) programs mplayer and lame. In theory, mplayer will download the appropriate files I tell it to and then lame will encode them from WAV to MP3. Both of the two previous functions (mplayer and lame) work great when I run them from a command line.

Now here's the thing, I tell java to execute the mplayer command using runtime.exec(). It begins the execution which should take a long time, as it is downloading a stream of audio, but then without missing a beat moves on and terminates my script application as if all went well. I used a BufferedReader to get the output from mplayer (really from the runtime object), and it spits me back the first 6 lines almost exactly as I get when I run mplayer directly from the command line. But I do not get the rest of it, which should be another 50ish lines. The code follows, pardon the ugliness of variable names.

any ideas are GREATLY appreciated
Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
You should read more about runtime.exec() and Process.

In the process you have an option to wait for exit value of the process.
Under unix (or OSX) you whould usually get 0 for all good and 1 for error.
So try to get the exit value and evaluate it.

you can get more info on JavaWorld:

Hope that helps.
I agree. Here's the link:
subject: calling unix application mplayer
It's not a secret anymore!