kindahero
kindahero

Reputation: 5867

Feeding input to a program with Perl?

I am not sure how to put this question. I am trying to write a Perl program which invokes a child program (a Fortran program) so child program goes to stdin to get yes/no.

Is there a way Perl can give that option, without letting child goes to STDIN?

Because of my poor programming vocabulary, I couldn't get an answer from Google.

Upvotes: 2

Views: 455

Answers (1)

ysth
ysth

Reputation: 98388

You can start a progam with its input coming from a pipe like so:

open my $ftn_input, '|-', $fortran_program
    or die "Couldn't start $fortran_program: $!";
if ($yes) {
    print $ftn_input "Yes\n";
}
else {
    print $ftn_input "No\n";
}
close($ftn_input) # waits for fortran program to complete
    or die "Program failed; error $!, wait status $?\n";

Upvotes: 3

Related Questions