2011-05-09 114 views
2

我不知道如何把這個問題。我正在嘗試編寫一個調用子程序(Fortran程序)的Perl程序,以便子程序轉到標準輸入以獲取是/否。使用Perl爲程序提供輸入?

Perl有沒有一種方法可以給出該選項,而不讓孩子去STDIN?

由於我的編程詞彙很差,我無法從Google獲得答案。

+0

如果其他程序使用標準輸入來獲得它的輸入又是什麼Perl的問題?這聽起來像你問的是一種方法來停止使fortran程序使用stdin? – Wes 2011-05-09 04:46:56

+2

聽起來你想要驅動另一個程序,Perl程序有點像'你'和Fortran程序提出問題並接收響應。你應該看看Expect.pm。另請參閱:http://stackoverflow.com/questions/1471018/how-can-i-control-an-interactive-unix-application-programmatically-through-perl – Alex 2011-05-09 05:00:26

+0

@Alex這就是我正在嘗試做什麼。謝謝。我可能會堅持使用管道,因爲它是一個小腳本。 – kindahero 2011-05-09 05:47:41

回答

3

可以開始從管道的輸入來像這樣一個編程':

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"; 
相關問題