Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why isnt my wait() and waitFor() working? please help



Shou ryuujo wrote:

>What do you mean by "exec{}'ing it directly"? You mean double click on
>quicktime Player or you mean this: process qt =
>Runtime.getRuntime.exec("/Applications/quicktime
>player/macos/contents/quicktime player"); ? I tried doing that but the
>console complains at the spaces between quicktime and player. I tried "\*"
>fix from windows, "\\" for a :"spa! ce" character and other methods but
>couldnt get it working.. any fix for that?

First, the String-cmd versions of exec() are not what you seem to think.

They do NOT create a shell that interprets a command-line String.  It is
impossible to "escape spaces" or use other shell notations (including \*),
because exec(String) is not a shell.  If you want a shell, you exec() a
shell command, e.g. "/bin/sh" or another shell of your choice, and then
feed it text on its stdin (the Process's "output stream").

Refer to the doc-comments for exec(String cmd,...), where it describes how
the tokenizing of the cmd-String is done using a StringTokenizer(cmd).  If
you then refer to StringTokenizer(String), you will see that white-space
separates tokens and no escaping, quoting, etc. is possible.

Second, the pathname is wrong in two ways:
  1. You've neglected the ".app" suffix on QuickTime Player's app-bundle.
  2. The sub-structure within the app-bundle is not "macos/contents".

The correct path to the executable in the app-bundle is:
  "/Applications/QuickTime Player.app/Contents/MacOS/QuickTime Player"

There are two embedded spaces, so this is not executable using the
single-String versions of Runtime.exec().  You must use the String[]
versions.


>Also, if it gets fixed and runs do I make another process - Process B=
>Runtime.getRuntime.exec("open " + file.getPath());? I dont see how opening
>quicktime first will affect the command "open"... if you can elaborate or
>provide example that would be greatly appreciated..

The strategy you are pursuing cannot easily be made to work, because QT
Player on Mac OS X will not exit when it finishes playing a media file.
That one capability, which exists on Windows but not on Mac OS X, is
fundamental to what you are trying to accomplish: detecting the end of
sound playback.  You could probably write AppleScript or perl that gets
around this, but then you're writing AppleScript or perl, not Java.

So if you're using Java, then no matter what else you did with the QT
Player process using Java, you'd still have to figure out a way for the QT
Player process to signal when it finished playing the audio file, so your
Java code knew the audio was finished.  That's just going round and round
in circles adding hack upon hack trying to get your Java program to play an
audio file and know when its done playing it.  It would be simpler to just
play the audio-file in Java itself, assuming it's an audio format
understandable to JavaSound.


>And by the way, i am trying to make a program where it receives incoming
>audio and plays it on quicktime then when that particular player closes it
>will send back to the other person another audio.

Have you considered using JavaSound?


If you're just looking for a quick hack, I don't think you're going to get
it using Runtime.exec() on Mac OS X, regardless of whether you get it
working acceptably on Windows.  The differences between Mac OS X and
Windows in how they act with processes and desktop applications are large
enough that such hacks are unlikely to work well, if at all.

Another possibility is to use a language other than Java on Mac OS X, that
has easily accessible synchronous audio-file playback, such as AppleScript,
perl, python, etc.  It would only have to interoperate with the sending
program on Windows.  They could be completely different implementations.

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.