Reputation: 3480
I have to light patch some of the core components within an internal software product. Due to its realy nasty handling of STDIN I have to:
Unfortunally I am not allowed to modify any of the legacy code so I have to light patch it.
My first not working try:
BEGIN {
my $stdin_raw = join '', <STDIN>;
use IO::Handle;
my $stdin_io1 = IO::Handle->new();
$stdin_io1->printflush( $stdin_raw );
my $stdin_io2 = IO::Handle->new();
$stdin_io2->printflush( $stdin_raw );
STDIN->fdopen( $stdin_io1, 'r' );
require CGI;
warn CGI::param('PARAM1');
warn CGI::param('PARAM2');
STDIN->fdopen( $stdin_io2, 'r' );
}
It's able to read STDIN in the first line but nighter CGI nor the downstream system are getting any input from STDIN which I (tried) to set as listed above.
So: How to read STDIN and write content back to STDIN in Perl?
The application is running under CGI (webserver) condition. STDIN handles the POST data of a web request.
Upvotes: 2
Views: 2679
Reputation: 385506
How about open(STDIN, '<', \$stdin_raw)
By the way,
my $stdin_raw = join '', <STDIN>;
is usually written as
my $stdin_raw; { local $/; $stdin_raw = <STDIN>; }
Probably more efficient too.
Upvotes: 2