in reply to Re^3: Reassign STDOUT/STDERR contents to a variable
in thread Reassign STDOUT/STDERR contents to a variable

Good stuff. Doesn't seem to work for my eval though..

print "Script content: $script_content\n"; print "Script input: $script_input\n"; open(SAVEOUT, ">&STDOUT"); open(SAVEERR, ">&STDERR"); close(STDIN); open(STDIN, '<',\my $stdin); #seek STDIN,0,0; # with or without, no diff. $stdin .= $script_input; #seek STDIN,0,0; # with or without, no diff. close(STDOUT); open(STDOUT,'>' , \my $stdout); close(STDERR); open(STDERR,'>' , \my $stderr); select(STDERR); $| = 1; select(STDOUT); $| = 1; eval $script_content; my $result_code = $@; close(STDOUT); close(STDERR); open(STDOUT, ">&SAVEOUT"); open(STDERR, ">&SAVEERR"); if ( ! $stderr ) { $stderr = ''; } # my db doesn't like nulls. if ( ! $stdout ) { $stdout = ''; } print "STDERR:" . $stderr; print "STDOUT:" . $stdout;

In all variations where I'm using STDIN that is tied to a variable, I still get the manpage. Argh.

I'm thinking the difference is that in your scenario you can do your writes to STDIN after the process has it. I think I have to have it set up prior to my eval, or my read of stdin within my evaled script will just return as it would get EOF immediately.