develooper Front page | perl.beginners | Postings from March 2002

Problems running Win32's "net use" with system()

Thread Next
From:
Francoys Crepeau
Date:
March 15, 2002 20:58
Subject:
Problems running Win32's "net use" with system()
Message ID:
003201c1cca7$2903bc80$c07ba8c0@yourze8cxvr8tt
Hi everyone! I hope someone can tell me what I'm doing wrong.

I'm running ActivePerl 5.6 on an NT4 (service pack 5) box. 

One of the things I have to do is to have a Perl script "map" a network
drive to a drive letter. 

When one manually does this from the command line, it is done using the
"net use" command, specifying as parameters the destination drive letter
(or a wildcard to get the first available one) and the network drive.

I'm trying to do this by calling system() from my Perl script, but the
call to system() fails. However, if I type the same command at the
command line, it works.

I thought at first that I might not be correctly invoking the system()
function, but I am able to use it to have the "dir" command executed.

Shown below is the source of my test program:

#***** START OF TEST PROGRAM
use strict;
use warnings;
use diagnostics;

# For unbuffered I/O.
$| = 1;

# Set up the arguments for the calls to system().
my( @sysargs0 ) = ( 'dir', '..' );
my( @sysargs1 ) = ( 'net use', '*',  '\\\\rndnt55\\rndapps' );

# Just do a call to the Win32's "dir .." command.
# Works OK.
system( @sysargs0 ) == 0
  or die( "system( \@sysargs0 ) failed: $?" );

# For verification, see what system() is receiving.
for( my $i = 0; $i <= $#sysargs1; $i++ ) {
  print( "\t\$sysargs1[ $i ] = $sysargs1[ $i ]\n" );
}

# This call to Win32's "net use" fails. !?!?!
if( system( @sysargs1 ) != 0 ) {
  my( $exitValue ) = $? >> 8;
  my( $signalNum ) = $? & 127;
  my( $dumpedCore ) = $? & 128;

  print( "\t\$exitValue = $exitValue\n" );
  print( "\t\$signalNum = $signalNum\n" );
  print( "\t\$dumpedCore = $dumpedCore\n" );

  die( "system( \@sysargs1 ) call failed: $?" );
}
#***** END OF TEST PROGRAM

************************************************************************
Francoys Crepeau
Ottawa, Ontario, Canada
mailto:crepeaufr@rogers.com 



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About