http://www.perlmonks.org?node_id=1025917


in reply to Re^2: Windows Net Use
in thread Windows Net Use

You found a material gap in my code. Problem is the escaped $ at the end. The backslash in front of it will be doubly escaped and then the $ will cause trouble.

use strict; my $inputDirectory = '\\\\10.81.253.140\\IPC$'; # need to dublicate each \ in string $inputDirectory =~ s|\\|\\\\|g; $inputDirectory =~ s|\$|\\x{24}|g; # replace $ with hex representatio +n my @lines = `net use`; foreach my $line ( @lines ) { next unless $line =~ m|$inputDirectory|; $line =~ /(^\S+)/; print $1; }

Replies are listed 'Best First'.
Re^4: Windows Net Use
by Anonymous Monk on Mar 28, 2013 at 10:08 UTC

    @hdb A few more doubts.. What was the exact problem caused when we used /$(dont know ehat is this material gap..)and Also Why are we duplicating \\ to \\\\ (line 3)

      I have to admit that I confused myself a bit. The problem with $ is that in the regular expression it is interpreted as end line and needs to be escaped. The \\ needs to be duplicated to escape it to a double \ again in the regular expression. The WMI approach proposed further down is probably safer...