Subject: | is_interactive() and command line arguments |
Date: | Tue, 06 Feb 2007 20:17:39 +0100 |
To: | bug-IO-Interactive [...] rt.cpan.org |
From: | Ireneusz Pluta <ipluta [...] wp.pl> |
Hello,
it seems that is_interactive() returns 0 when a script using IO::Interactive is invoked with any
command line parameters (causing @ARGV > 0).
Here is my test script and its output when invoked without and with a parameter:
526-ipluta@perkoz:~/debug$ cat interactive.pl
#!/usr/bin/perl -w
use IO::Interactive qw(is_interactive);
if (is_interactive()) {
print "interactive\n\n";
}
else {
print "NOT interactive\n\n";
}
527-ipluta@perkoz:~/debug$ ./interactive.pl
interactive
528-ipluta@perkoz:~/debug$ ./interactive.pl param
NOT interactive
Is this a bug?
However, a quick hack with making a local @ARGV empty and testing is_interactive() in a code block
seems to work for me:
531-ipluta@perkoz:~/debug$ cat interactive1.pl
#!/usr/bin/perl -w
use IO::Interactive qw(is_interactive);
{
local @ARGV = ();
if (is_interactive()) {
print "interactive\n\n";
}
else {
print "NOT interactive\n\n";
}
}
532-ipluta@perkoz:~/debug$ ./interactive1.pl
interactive
533-ipluta@perkoz:~/debug$ ./interactive1.pl param
interactive
I am not sure if this is a correct universal workaround. But even if that, this case is not
mentioned anywhere in the documentation, so I am sending this post.
Some more details of my system:
535-ipluta@perkoz:~/debug$ perl -MIO::Interactive -e 'print IO::Interactive->VERSION, "\n";'
0.000003
536-ipluta@perkoz:~/debug$ perl -v
This is perl, v5.8.6 built for i386-freebsd-64int
<...>
537-ipluta@perkoz:~/debug$ uname -a
FreeBSD perkoz.cmr.net.pl 4.10-RELEASE FreeBSD 4.10-RELEASE #6: Mon Sep 20 11:29:40 CEST 2004
ipluta@perkoz.omd.pl:/usr/src/sys/compile/PERKOZ i386
Best regards
Ireneusz Pluta