in reply to need both from system-call

Well, it's not very elegant but what I would do is use the system call and redirect the output to a file and then open that file
my $return_code = system("system_command > /tmp/program.out"); open(FILE,"/tmp/program.out") || die "Cant open /tmp/program.out $!\n" +; my @output_file = <FILE>; close FILE; unlink("/tmp/program.out"); print STDOUT "return code ",$return_code>>8,"\n"; print STDOUT "@output_file";

Replies are listed 'Best First'.
Re: Re: need both from system-call
by rob_au (Abbot) on Apr 27, 2001 at 19:45 UTC
    While others have posted links to other code that achieves physi's desired result, there is something which I think needs to be addressed in your code. While it certainly works and allows for a range of exit result eventualities, it does raise the age-old ire of using temporary files on systems. That is, the use of tempoary files with either predictable or known file names can allow for the trapping and redirection of output code.

    Issues pertaining to the use of temporary files have been covered in a number of threads both on Perl Monks and on news groups, including here and here. I would also recommend having a look at the POD documentation for the File::Temp module which discusses temporary file issues.

    I just wish I had saved the thread from comp.lang.perl.moderated that dealt with this issue in detail. At the very least I hope I have got you thinking ...

      I just wish I had saved the thread from comp.lang.perl.moderated that dealt with this issue in detail. At the very least I hope I have got you thinking ...

      This thread from comp.lang.perl.modules disusses temporary files in detail.