On 7/20/07, Gregory Machin <[EMAIL PROTECTED]> wrote:
Hi
can you advise on the best way test if a usb modem is plugged in ?
I though about checking if the file/node /dev/ttyACM0 is present, as
it's created when the device is plugged in using open (TEST,
"/dev/tty/ACM0"); but just concecned if i do this while the device is
acitive it will cause it to drop the connection... What is the best
methode for this ??

This is highly OS dependent; however, most OSes provide a utility like
ifconfig that can report on the status of network interfaces.  Another
option (at least under many UNIX flavors) is to use lsof (list open
files) to check to see if the file is already open:

#!/usr/bin/perl

use strict;
use warnings;

$! = 0;
if (my $out = `lsof $ARGV[0]`) {
       die $out if $?;
       print "$ARGV[0] is open\n";
} else {
       print "$ARGV[0] is closed\n";
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to