Ramprasad wrote:
I have written a simple script that runs file when I run on command line but fails when I redirect its output
I cant beleive this , it seems so impossible can anyone help me
$!=1;
Should be $| = 1 for autoflush. Or, more neatly:
use IO::Handle; autoflush STDOUT;
use Net::Ping; @host_array = <DATA>; $p = Net::Ping->new("icmp"); $p->bind("192.168.2.211"); # Specify source interface of pings
I don't know of a 'bind' method for this module. I may be new, of course.
foreach $host (@host_array) { chomp($host); print "$host is "; print "NOT " unless $p->ping($host, 2);
I'd try the program with the ping line commented out, so that all it's doing is dumping your data. Then see if you can redirect that.
print "reachable.\n"; } $p->close(); __DATA__
[snip data]
When I run the above script it runs fine like this perl ping1.pl
when I do perl ping1.pl >output I get nothing on screen the file output is also empty 8-(
Now How can this happen
I can't imagine! But try writing a simple 'Hello World!' program and making sure you can redirect from that, then enhance it stepwise until it does what this one does!
DO let us know when you find the answer!
Cheers,
Rob
Thanks all ,
It was a problem of buffering after all most probably.
my typo $!=1 instead of $|=1 was the culprit.
I just went straight home yesterday and today morning i did $| =1 and all's well
But I am not very sure about the problem
If the program is buffering ( assume I do not put $|=1 )
then the program must flush the buffer when it exits . So when I do a Ctrl-C the output file must get created !?! , or is it that the buffer is cleared only if the program reaches the end
BTW using IO::Handle is a clean way but an overkill, My code takes a full second extra if I put a use IO::Handle ( I am using redhat linux 7.2 and perl 5.8.0 )
Thanks Ram
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]