in reply to Re: Silencing errors in a php script using perl nd pipes.
in thread Silencing errors in a php script using perl nd pipes.

Thanks very much for your helpful reply! I tried the native bourne shell and it worked. I did try the 2nd option for interests sake and although it didn't output an error it also didn't run my php script on the email. Could you shed any light on why the STDIN is not routed to the php when executed from perl?
  • Comment on Re^2: Silencing errors in a php script using perl nd pipes.

Replies are listed 'Best First'.
Re^3: Silencing errors in a php script using perl nd pipes.
by ikegami (Patriarch) on Jun 20, 2008 at 07:58 UTC

    I'm guessing that the Perl script's STDOUT and STDERR are getting closed, sending a SIGPIPE to the email server, making it think the child exited. I don't know why it doesn't occur for the first snippet.

    It could be prevented by replacing exec with system if I'm right about the cause. Don't forget to make the call to die conditional or remove it for testing.

    A better system would expand on the third snippet to filter out the expected message while letting anything else through. Turns out it's pretty simple since we don't have to deal with the child's STDOUT, just its STDERR.

    #!/usr/bin/perl use strict; use warnings; use IPC::Open3 qw( open3 ); use Symbol qw( gensym ); my $pid = open3( \*STDIN, \*STDOUT, my $fr_chld_err = gensym(), './home/bevs/bin/email' ); while (<$fr_chld_err>) { next if /Module 'eAccelerator' already loaded/; print STDERR $_; } waitpid($pid, 0) or die;
      For that last bit of code. If I remove the . from './home/bevs/bin/email' the php script runs but does not get the email when it reads its STDIN...
      #!/usr/bin/perl use strict; use warnings; use IPC::Open3 qw( open3 ); use Symbol qw( gensym ); my $pid = open3( \*STDIN, \*STDOUT, my $fr_chld_err = gensym(), '/home/bevs/bin/email' ); while (<$fr_chld_err>) { next if /Module 'eAccelerator' already loaded/; print STDERR $_; } waitpid($pid, 0) or die;
      How do I modify that perl code to pass the standard input on?
        For reasons I don't understand at the moment, passing \*STDIN and \*STDOUT doesn't work. The following does, though.
        my $pid = open3( '<&STDIN', '>&STDOUT', my $fr_chld_err = gensym(), 'email' )

        Tested as follows:

        File wrapper:

        #!/usr/bin/perl use strict; use warnings; use IPC::Open3 qw( open3 ); use Symbol qw( gensym ); my $pid = open3( '<&STDIN', '>&STDOUT', my $fr_chld_err = gensym(), 'email' ); while (<$fr_chld_err>) { next if /Module 'eAccelerator' already loaded/; print STDERR $_; } waitpid($pid, 0) or die;

        File email:

        #!/usr/bin/perl use strict; use warnings; use IO::Handle qw( ); STDOUT->autoflush(1); STDERR->autoflush(1); print STDERR ("PHP Warning: Module 'eAccelerator' already loaded in U +nknown on line 0\n"); print STDOUT ("[STDOUT]\n"); print STDERR ("[STDERR]\n"); while (<STDIN>) { print STDERR (">> $_"); }
        $ echo meow | wrapper [STDOUT] [STDERR] >> meow