in reply to Re^2: perl robocopy to temp mapped drive.
in thread perl robocopy to temp mapped drive.

Try adding pipe to open

    open TASK, '-|',"net use \* \"$_[0]\"" or die "cannot map $_[0]";

or alternatively

#!perl use strict; use warnings; use IPC::System::Simple qw/capture/; my $destination = "\\\\BLAH\\NESTED\\OBFUSCATED\.WITH SPECIAL_CHARS\\S +HARE\\NAME\\DOWN\\DEEP"; print netUse($destination); sub netUse { my $path = shift; my $cmd = "net use * $path"; my ($msg) = grep /Drive/, capture($cmd); return ($msg =~ /Drive (.*) is now connected/); }
poj

Replies are listed 'Best First'.
Re^4: perl robocopy to temp mapped drive.
by 3dbc (Monk) on Oct 11, 2018 at 17:53 UTC
    I needed to add the 2>&1| guess that's the pipe you're talking about. Thanks.
    sub netUse { my @net_use_output; my $output; chomp $_[0]; $_ = $1 if($_[0]=~/(.*)\\$/); print "\nnet use \* \"$_[0]\""; #my $output = `net use \* \"$_[0]\" 2>&1|`; open TASK, "net use \* \"$_[0]\" 2>&1|" or die "cannot map $_[0]" +; while (<TASK>) { print "\n"; print; #chomp; #chop; push (@net_use_output, $_); #return $_; } print join(", ", @net_use_output); print "\n"; print "\n"; print "-----\n"; print @net_use_output[0]; $output = $2 if(@net_use_output[0]=~/^(Drive\s)([A-Z])\:(.*)$/); print "\n"; print "\n"; print "-----\n"; print $output; #return @net_use_output; }
    Returns:
    net use * "\\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHARS\SHARE\NAME\DOWN +\DEEP" Drive S: is now connected to \\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHA +RS\SHARE\NAME\DOWN\DEEP. The command completed successfully. Drive S: is now connected to \\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHA +RS\SHARE\NAME\DOWN\DEEP. , , The command completed successfully. , ----- Drive S: is now connected to \\BLAH\NESTED\OBFUSCATED.WITH SPECIAL_CHA +RS\SHARE\NAME\DOWN\DEEP. ----- S
    - 3dbc