我通過使用管道的Perl腳本將命令傳遞給某些應用程序。 所以我在管道上寫命令。但是我的問題是,管道並沒有等待命令執行從應用程序端結束,並且它接受了下一個命令。所以在命令執行結束之前它不會阻塞輸入。我需要我的Perl腳本像UNIX shell一樣工作。但它發生就像進程運行到後臺一樣。我使用readling來讀取輸入。在perl中寫入管道
#!/usr/bin/perl -w
use strict;
use Term::ReadLine;
open (GP, "|/usr/bin/gnuplot -noraise") or die "no gnuplot";
use FileHandle;
GP->autoflush(1);
# define readline
$term = new Term::ReadLine 'ProgramName';
while (defined($_ = $term->readline('plot>'))) {
printf GP ("$_\n");
}
close(GP);
我猜高水平,管道必須發送每條命令後關閉。不確定。 – 2013-03-09 11:14:45
請不要關閉管道,但應等到執行結束。 – snkatore 2013-03-09 14:08:35
嘗試[IPC :: Open3](http://perldoc.perl.org/IPC/Open3.html) – Alec 2013-03-09 16:09:03