--------------enigDE123CD86784007FD741E0DD
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Phlip wrote:
> I want a solution inside the Rakefile. And I want Someone Else, preferrably 
> a Ruby library, to take care of the 'if' statement that detects the 
> platform.
> 

Unfortunately, rake doesn't seem to let you check for failure of
dependent tasks - if a task fails, all goes pear-shaped and the process
exits, that's it. Short of a change to Rake to use for example a
TaskFailedError that Task#execute / Task#invoke would throw (HINT) you
could catch and rethrow, that just isn't doable.

See below why platform sniffing isn't quite necessary if you're willing
to depend on a cross-platform media player.

> The current solution looks like this:
> 
>         got = system(command)  # <-- shells to rake
> 
>         sound  = if got
>                           'drumloop.wav'
>                       else
>                           'jaguar.wav'
>                       end
> 
>         weWin32 = RUBY_PLATFORM.include?('mswin32')
> 
>         if weWin32
>             system('"C:\\Program Files\\Windows Media Player\\mplayer2.exe" 
> /play /close s:\\bin\\' + sound)
>         else
>             system('aplay ~/bin/' + sound)
>         end
> 
> That sucks bigtime, for many various reasons. Windows is too awesome and 
> sophisticated to provide a true command-line solution; we are calling 
> 'system', etc.
> 

Windows, in its awesomeness and sophistication, has a unified way of
opening documents with their default handlers from the command line.

system('start s:\\bin\\#{sound}') would've worked.

Provided mplayer.exe (or any other cross-platform media player program)
is on PATH:

If you registered mplayer as the default handler for .wav files ("ftype
soundrec=mplayer %1"), this would work without opening an unsightly window.

Please refrain flaming at the Windows command line when it's in fact
your ignorance of how it actually works showing. It's sad to look at and
all. I'm not saying there isn't anything to flame about either Windows
or its command line, but this isn't it - both Windows and Linux will
launch a program on PATH, the only difference is that with the Linux
directory structure, usually all software on your computer will be in
PATH already by convention.

Of course, if mplayer.exe is on PATH on your Windows box, and also on
your Linux box, provided you can find the .wav file you want to play
using a pathname relative to some parameter accessible at runtime (the
script location), you don't need any OS sniffing whatsoever. As of
Windows XP, system() will happily accept any combination of forward or
backward slashes in the filename whatsoever. Which means the script will
work cross-platform. As for the system() call, I'm afraid there's very
little you can do. To my best knowledge, there just is no in-process
audio framework with a Ruby binding that comes with anything close to an
installation method requiring less effort than getting the sound to play
is worth.

> Now here's the fire to light under this thread - the reason I want a 
> solution inside the Rakefile, and portable:
> 

>   --> Ant does this out of the box <--
> 

java.sound being around since 2001, I'm somehow not surprised. The Ruby
standard library having... well... no multimedia support whatsoever, I'm
not surprised Rake doesn't.

David Vallner


--------------enigDE123CD86784007FD741E0DD
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFTko4y6MhrS8astoRAgMIAJsEFbo0IRi+wgpPZGpezgFu8BUChwCfd3+W
d7aUQEqbhvgK8mNoYRVPHAIat
-----END PGP SIGNATURE-----

--------------enigDE123CD86784007FD741E0DD--