[TAG] Another 2 cent tip for you
lpitcher at sympatico.ca
Thu Jun 23 03:17:36 MSD 2005
-----BEGIN PGP SIGNED MESSAGE-----
I sent this in a couple of months ago, but it seems to have disappeared into
the aether and not made it to your fine publication. So, assuming that it
wasn't rejected, but had just been missed, I decided that I should try again.
Here's a little tip I gathered from some conversation going on in the
alt.os.linux newsgroup a couple of months ago. I contacted the people
involved in the news thread and they all agreed that I could submit the
conclusions of the thread as a Two Cent Tip (with proper accreditation, of
course). So, thanks to Michael Heiming and Chris F. A. Johnson, here's a Two
Cent Tip for you...
Over in news:alt.os.linux, a reader posted a question that asked how to make
Linux use "file associations" (sort of like MSWindows) so that the user just
types the name of the data file at the commandline, and the sutiable
application starts up and processes it. The example was wanting xmms to play
an MP3 just by typing the MP3's filename at the command prompt.
This lead into a discussion amongst various alt.os.linux participants,
primarily Michael Heiming and Chris F.A. Johnson, about "binfmt_misc", and
how it could be used to satisfy MSWindow'ish "file associations". For those
who don't know, you can "register" a command interpreter through a /proc
entry, so that, when you try to run a file that needs that command
interpreter, the system will start up the program for you. This is how Linux
recognizes executable shell scripts in order to start the shell interpreter
on them, and how it recognizes executable java byte code, in order to run the
java interpreter on it, when you type it's name at the command prompt.
To use this feature, you need to mount the "binfmt_misc" pseudo-filesystem, so
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
(or add the appropriate line to your /etc/fstab, and have it mounted
automatically at the next boot). Now, (again, as root) tell Linux what
interpreter to use by "echo"ing an association string into
the /proc/sys/fs/binfmt_misc/register pseudo-file. In this case, we want to
the string to indicate that any 'executable' file with the 'extension'
of .mp3 is to be interpreted by /usr/bin/xmms, so the
registration strings are
echo ":xmms:E::mp3::/usr/bin/xmms:" > /proc/sys/fs/binfmt_misc/register
echo ":mps:E::mp3::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
echo ":ogg:E::ogg::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
echo ":m3u::E:m3u::/usr/bin/xmms:" >/proc/sys/fs/binfmt_misc/register
Now, when we (as a regular user)
~ $ chmod u+x my_life_changed.mp3
~ $ my_life_changed.mp3
up pops XMMS and the music plays on.
The format and variations of the "registration" string are documented
My thanks to Michael Heiming and Chris F. A. Johnson for pointing out
how to do this.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
-----END PGP SIGNATURE-----
More information about the TAG