mallen has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone every used ipconfig /release and ipconfig /renew in a Perl script. If so, can you let me know who you used it. Thanks,

Replies are listed 'Best First'.
Re: Using IPConfig
by inman (Curate) on Apr 11, 2005 at 15:14 UTC
    The easiest way would be to use backticks to execute the application and capture the output.
    my $ipconfig = `ipconfig /renew`; # test the output of the ipconfig command here.

      I am a beginner, so beware.

      When I do this, I would do:

      my $ipconfig = `ipconfig /renew`; my $ipcfg_success = $?; if ($ipcfg_success == 0) { do something; } else { do something; }

      or, to test:

      my $ipconfig = `ipconfig /renew`; my $ipcfg_success = $?; die "command failed: $?" unless $ipcfg_success == 0;

      If these are wrong, please say so, so I don't do them again ;-)

      But remember, $? is the status returned by the last pipe close, backtick (``) command, successful call to wait() or waitpid(), or from the system() operator. Therefore, be careful where you put it, i.e. don't define it at the top of your program and expect it to work.

      For $? see perlvar and for other ways to execute commands, see exec and system functions.

      Thanks.

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!