Interprocess Communication (IPC)
To maximize portability, don’t try to launch new processes. That means you should avoid
system, exec, fork, pipe, ``,
qx//, or open with a |.
The main problem is not the operators themselves; commands that launch external processes are generally supported on most platforms (though some do not support any type of forking). Problems are more likely to arise when you invoke external programs that have names, locations, output, or argument semantics that vary across platforms.
One especially popular bit of Perl code is opening a pipe to sendmail so that your programs can send mail:
open(MAIL, "|/usr/lib/sendmail –t") || die "cannot fork sendmail: $!";
This won’t work on platforms without sendmail. For a portable solution, use one
of the CPAN modules to send your mail, such as Mail::Mailer and Mail::Send in the MailTools distribution, or Mail::Sendmail.
The Unix System V IPC functions (msg*(), sem*(), shm*()) are not always
available, even on some Unix platforms.
The IPC::Run, IPC::System::Simple, and Capture::Tiny CPAN
modules can help manage some cross-platform issues with external
commands.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access