in reply to Re: Re: Re: Re: Redirect file write from external program to STDOUT
in thread Redirect file write from external program to STDOUT

Usiing CON as the filename will only get the output to the command line. To capture it into the program you should use open instead. Something like

open IN, "echo $script | $program |" or die $!; binmode IN; my $img = do{ local $/; <IN> }; close IN;

See perlopentut for the details of grabing program output using open. This is necessary as you will need to use binmode to prevent the stream being interupted by ^Z.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


  • Comment on Re: Re: Re: Re: Re: Redirect file write from external program to STDOUT
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Redirect file write from external program to STDOUT
by chunlou (Curate) on Jun 26, 2003 at 23:36 UTC
    If I do this MyPerl.PL > plot.jpeg, isn't this script
    `echo $script | $program`;
    and this script
    open IN, "echo $script | $program |"; binmode IN; my $img = do{ local $/; <IN> }; close IN; binmode STDOUT; print $img;
    the same? In any case, the jpeg produced was always something of a dozen bytes size or so, certainly not jpeg.

    Since the binmode, open and all technique works with GD, I wonder if that external program simply somehow fails to generate a jpeg properly with CON as filename. Just afraid to waste people time if the problem is totally exogenous to Perl.

    Thanks for bearning with me.