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

So I need to use "NET USE" in a Perl script to map a Network drive andi am having an issue i believe it has to do with the password having a "$" in it.

$pw = 'TBHxD6$e60r--rjt&'; my $cmd = "NET USE g: \\\\<NETWORK DRIVE>\\<NETWORK FOLDER> $pw /user: +<USERNAME>"; warn $cmd; # whoops!! system($cmd); print "done";

If i enter the exact line from the command line with the same password it works fine but not in Perl.

Replies are listed 'Best First'.
Re: Password with special characters (updated)
by haukex (Archbishop) on Jun 24, 2019 at 17:42 UTC

    I wrote about this topic at length here. In this case, assuming this is on Windows, you might want to just use Win32::ShellQuote, e.g. its quote_system_list - but make sure to read the module's documentation in any case.

    Update: For example, system(quote_system_list('NET','USE','g:','\\\\<NETWORK DRIVE>\\<NETWORK FOLDER>',$pw,'/user:<USERNAME>'))==0 or die "system failed, \$?=$?";

      Thank you for your help it sent me in the right direction and I was able to use ShellQuote::Any::Tiny qw(shell_quote) to get my command to run. Have a great day.