[Mimedefang] open(FOO, "bar |") vs. `bar`

Jan Pieter Cornet johnpc at xs4all.nl
Tue Nov 1 03:36:54 EST 2005


On Mon, Oct 31, 2005 at 03:02:40PM -0800, Matthew.van.Eerde at hbinc.com wrote:
> I've been experimenting with various MIMEDefang features...
> I notice that the Virus:BDC plugin in particular does an open(HANDLE,
> "command |") call to capture the output, whereas my Spamc feature uses
> `spamc`...
> 
> I see that open(FOO, "bar |") allows you to capture the return code,
> which is nice.

So does `backtick`. The return code is in $?. See "man perlvar".

> Where could I read up on the comparative benefits of open(FOO, "bar
> |") vs. `bar` vs system("bar") etc.?

"man perlfunc", "man perlop" and "man perlipc" to some extent.

The main differences between open(PIPE, "... |") and `backtick` are:
. open PIPE allows you to read the return stream piece by piece as it
  arrives, whereas:
. backtick operator give you the entire output, as a string, the moment
  the external command finishes.
. shell meta characters in the command will spawn the command via your
  shell in both cases. However, open PIPE has an alternative syntax which
  allows you to always force direct execution of the command, regardless
  of any shell metacharacters in the arguments.
. You should take care not to create zombies or runaway processes when
  you use a timeout mechanism like a SIGALRM. At least open PIPE will
  return the pid of the subprocess, allowing you to kill(2) it or wait(2)
  on it.

As usual, the perl motto "TIMTOWTDI" applies here. It seems that in your
case, you just want to run spamc, wait for it to complete and grab the
entire output. For that application, using backticks is certainly the
easiest way to do it.

-- 
#!perl -wpl # mmfppfmpmmpp mmpffm <pmmppfmfpppppfmmmf at fpffmm4mmmpmfpmf.ppppmf>
$p=3-2*/[^\W\dmpf_]/i;s.[a-z]{$p}.vec($f=join('',$p-1?chr(sub{$_[0]*9+$_[1]*3+
$_[2]}->(map{/p|f/i+/f/i}split//,$&)+97):qw(m p f)[map{((ord$&)%32-1)/$_%3}(9,
3,1)]),5,1)='`'lt$&;$f.eig;                                # Jan-Pieter Cornet



More information about the MIMEDefang mailing list