2
#!/usr/bin/perl -w
use Term::ReadKey;
ReadMode('cbreak');
while (1) {
$char = ReadKey(-1);
next unless defined $char;
printf("Char: $char Decimal: %d\tHex: %x\n", ord($char), ord($char));
}
ReadMode('normal');
以上工作很好。但我希望能夠在某些可執行文件正在運行時獲得用戶輸入。所以我試了下面,但它不工作。也許運行一個可執行文件,而試圖獲得用戶輸入是搞亂了?如果是這樣,我該如何去做呢?Perl無阻塞用戶輸入
我正在從$ myexe輸出,並根據用戶的輸入,我想從$ myexe
#!/usr/bin/perl -w
use Term::ReadKey;
my $myexe = 'bin/myexecutable';
open my $EXE,
"$myexe distribute 2>&1 |"
or die 'Cannot open EXE';
ReadMode('cbreak');
while (<$EXE>) {
$char = ReadKey(-1);
if (defined $char) {
print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $char\n"; #i would press a key but nothin prints out
}
print "$_\n";
}
ReadMode('normal');
'bin/myexecutable distribute'的輸出是什麼? – rubikonx9 2015-02-11 07:58:12
@g.tsh一串字符串。例如,「building」 –
ealeon
2015-02-11 08:00:13
@ g.tsh是bin/myexecutable的輸出與我能夠獲取用戶輸入? – ealeon 2015-02-11 08:00:46