Re: Net::Ping Cannot redirect output !
R. Joseph Newton wrote: $p-bind(192.168.2.211); # Specify source interface of pings [with no my or our] But it's a method call on an existing object ;-) /R -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net::Ping Cannot redirect output !
Rob Dixon wrote: R. Joseph Newton wrote: $p-bind(192.168.2.211); # Specify source interface of pings [with no my or our] But it's a method call on an existing object ;-) Oops, my bad. cited the wrong line--should have been: $p = Net::Ping-new(icmp); and this may even have been declared somewhere earlier, but, somehow, I doubt it. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Net::Ping Cannot redirect output !
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; use Net::Ping; @host_array = DATA; $p = Net::Ping-new(icmp); $p-bind(192.168.2.211); # Specify source interface of pings foreach $host (@host_array) { chomp($host); print $host is ; print NOT unless $p-ping($host, 2); print reachable.\n; } $p-close(); __DATA__ 192.168.2.1 192.168.2.21 192.168.2.25 192.168.2.212 192.168.2.213 192.168.2.214 192.168.2.215 192.168.2.211 127.0.0.1 192.168.2.144 192.168.2.100 192.168.2.101 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 Thanks Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net::Ping Cannot redirect output !
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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net::Ping Cannot redirect output !
Rob Dixon wrote: 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]