• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

runtime exec - mplayer doesn't complete

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having problems with the exec command. I have mplayer set up to download a stream to disk (thus allowing me to listen to a live broadcast on my ipod later). I was trying to wrap this functionality into a small java program to do a few other things with it. The only way I know to run a unix program, mplayer, from java is with Runtime.exec().

So here is what I have:
try
{
Runtime rt;
rt = Runtime.getRuntime();
System.out.println("1");
Process p = rt.exec("mplayer -playlist ~/Desktop/new.txt -ao pcm -aofile ~/mystream.wav -vc dummy -vo null");
Process p = rt.exec(arg);
int val = p.waitFor();
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
while ( (line = br.readLine()) != null )
{
System.out.println(line);
}
System.out.println("2:rtn Val: "+val);
}
catch (Exception e)
{
e.printStackTrace();
}

and the output is:
matt:~/development/java/StreamToMP3 matt$ java StreamToMP3
1
MPlayer dev-CVS-040614-08:32-3.3 (C) 2000-2004 MPlayer Team

AltiVec found
CPU: PowerPC
Reading config file /usr/local/etc/mplayer/mplayer.confReading config file /Users/matt/.mplayer/config
2: rtn Val: 1



As you can see, it starts to run the mplayer command. But, it doesn't finish. The file it tries to download is not complete, in fact it never even creates the file "mystream.wav". I would think that using the p.waitFor() would make this happen, but it doesn't seem to.

Any thoughts?

[ July 09, 2004: Message edited by: Matt Zollinhofer ]
[ July 09, 2004: Message edited by: Matt Zollinhofer ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just guessing: You may have trouble that waitfor() waits for the process to finish, but it can't finish because you aren't reading from the outputs yet. Put your reader for stdout on another thread and fire it up before you waitfor(). And make another one for errout just in case. You might have good luck with join() on the reader threads instead of waitfor(). I had one program where the readers finished well after waitfor() returned.
 
Matt Zollinhofer
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I put the output stuff in a different thread, but it didn't seem to help. It looks like mplayer is returning early, but I don't get any feedback while. If you notice above, I print out what the process returns, and it returns a 1, not the standard 0 for exiting properly.

I don't know why mplayer would return something if it wasn't finished, but that seems to be whats happening. Am I totally missing something?

matt
 
Matt Zollinhofer
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, it doesn't hang at all. It just goes right through and terminates as if everything was fine. But it didn't do everything that the mplayer should have done if it was finished. And of course I did test the mplayer command in the command line by itself to make sure that it was a valid command.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic