in reply to Re: How a web server sending data to a CGI perl script ?
in thread How a web server sending data to a CGI perl script ?

come to think of it, Perl's open is not entirely appropriate for redirecting. It's better to use low-level dup2, otherwise there are some bad interactions when standard streams are already closed (which must be the case for a server).
if ( $pid == 0 ) { close $input_to_child; close $output_from_child; if ( fileno $child_stdout != POSIX::STDOUT_FILENO ) { POSIX::dup2( fileno $child_stdout, POSIX::STDOUT_FILENO ); close $child_stdout; } if ( fileno $child_stdin != POSIX::STDIN_FILENO ) { POSIX::dup2( fileno $child_stdin, POSIX::STDIN_FILENO ); close $child_stdin; } exec {'perl'} 'perl', 'client.pl'; }

Replies are listed 'Best First'.
Re^3: How a web server sending data to a CGI perl script ?
by Anonymous Monk on Jan 21, 2016 at 14:50 UTC
    which must be the case for a server
    come to think of it more, that shouldn't be the case... I must be tired today :) Anyway, I changed the code mainly because I always thought Perl's open used dup2, but then I checked the doc and it actually says: dup(2). So it's probably better to use POSIX::dup2 directly.