[TAG] Another 2 cent tip for you, courtesy of news:alt.os.linux
Lew Pitcher
lpitcher at sympatico.ca
Tue Mar 15 01:46:32 MSK 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
as root,
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
and then
~ $ my_life_changed.mp3
up pops XMMS and the music plays on.
The format and variations of the "registration" string are documented
in /usr/src/linux/Documentation/binfmt_misc.txt.
Kewl, eh?
My thanks to Michael Heiming and Chris F. A. Johnson for pointing out
how to do this.
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
_______________________________________________
Wftl-lug mailing list
Wftl-lug at salmar.com
http://www.salmar.com/mailman/listinfo/wftl-lug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFCNhROagVFX4UWr64RAtuDAJ4ho4CkpK7xl1i7/Rj97JPpfkPzygCgxOzK
OV8SvkDsBcVPRwQw0sIq05o=
=+02x
-----END PGP SIGNATURE-----
More information about the TAG
mailing list