开发者

Feeding input to a program with Perl?

开发者 https://www.devze.com 2023-03-04 01:12 出处:网络
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.

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, wi开发者_JS百科thout letting child goes to STDIN?

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


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";
0

精彩评论

暂无评论...
验证码 换一张
取 消