[Memphis.pm] Re: [Golum-nontech] need suggestion on Windoze (programming)

Brock Sides philarete at mindspring.com
Fri Jun 8 20:12:58 CDT 2001


* Ray Tant <Tant-R at co.shelby.tn.us> [010608 19:43]:

> Get Mac of Local Nic:
> #!/usr/bin/perl -w
> use strict;

Since you've used strict, and so are obviously interested in doing the
RIGHT THING...

> open (MAC, "/sbin/ifconfig |");

open (MAC, "/sbin/ifconfig |") or die $!;

If you're using perl < 5.6 you should also 

close MAC or die;

when you're done. The reason for this is, in perl <= 5.5, the return
value of a system call to open a pipe would only be false if the fork
failed. In 5.6 it will be false if either the fork or the exec fail.

[brock at harmless brock]$ perl -v

This is perl, version 5.005_03 built for ppc-linux

[brock at harmless brock]$ perl -e 'open (PIPE, "|/no/such/program") or die $!'
[brock at harmless brock]$ 

[brock at grunt brock]$ perl -v

This is perl, v5.6.0 built for i386-linux

[brock at grunt brock]$ 'open (PIPE, "|/no/such/program") or die $!'
bash: open (PIPE, "|/no/such/program") or die $!: No such file or
directory
[brock at grunt brock]$ 

However, the attempt to close the pipe will return false:

[brock at harmless brock]$ perl -e 'open(PIPE, "|/no/such/program"); close
PIPE or die $!'
Died at -e line 1.

Always check the return value of system calls.

-- 
Brock Sides
philarete at mindspring.com

One OS to rule them all, one OS to find them,
One OS to bring them all and in the darkness bind them,
In the land of Redmond, where the shadows lie.
----------------------------------------------------------------------------
To unsubscribe, please send email to majordomo at pm.org
with 'unsubscribe memphis-pm-list' in the body of the message.
----------------------------------------------------------------------------




More information about the Memphis-pm mailing list