Fix what ikegami says. You might also consider handling the redirection yourself. It doesn't make much difference if the shell does it or if perl does it, but from perl, it might just be more readable (or at least more pliable). You could also possibly alter the output on the way through:
use strict; # consider this also use warnings; # consider this also open my $input, "-|", "./hello.exe" or die "woops: $!"; open my $output, ">", "output.txt" or die "darn: $!"; while(my $line = <$input>) { # optionally do things here print $output $line }

(autodie seems to be more fashionable than my or dies too.)

In any case, doing the above would have complained more perlishly (perhaps) than the shell. It'd be more reliable if you could use the list version of the open popen. If it won't hurt anything it might even help to call it like this: open my $input, "-|", qw(./hello.exe 1) or die "popen fail: $!". If you can use the list version of open, you definitely get a perl error since the shell isn't even involved!

-Paul


In reply to Re: Running a C program from Perl by jettero
in thread Running a C program from Perl by n4nature

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.