MH & nmh: Email for Users & Programmers
Using MH from Other Languages
Programs that use MH commands don't have to be interpreted by the
Bourne shell, of course. An MH command may be run by any language
that will start a UNIX process and can:
In a lot of cases, the program will do its own processing of text
output by MH commands. For instance, Perl is good at parsing the
headers of email messages. So, instead of using MH format strings,
a Perl script might use
show -noshowproc or mhpath to read a message header
into an array -- then use Perl regular expression operators to get
the information you need.
Pass command-line arguments to the process.
Pass environment variables to it.
Pass text to the standard input of the process and read its
When you're trying to decide whether to use MH features or the
features of your language, how do you choose?
Get familiar with all the features of MH. Compare them to the
features in the languages you might choose as a "wrapper" around
MH commands. MH was designed for use in programming, so there
are lots of "hooks" for programming. Knowing about these hooks
can save you a lot of time "re-inventing the wheel" in another
Think about efficiency. On many systems, especially busy ones,
getting a UNIX process started takes a lot of time. Can you
MH command version that does what you
need -- without starting a "wrapper" process around the MH
command? How much clock time does your "wrapper" need to start
running before it executes the MH command? On the other hand,
can your interpreter do the work of several MH commands in its
own single process, thereby saving execution time?
This file is from the third edition of the book MH & xmh: Email
for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek.
It is freely available; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation. For more information,