Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Windows Net Use

by Anonymous Monk
on Mar 28, 2013 at 09:05 UTC ( #1025911=note: print w/replies, xml ) Need Help??


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

Thnks hdb .. But when i input the directory as

my $inputDirectory = "\\\\10.81.253.140\\IPC\$";

It does not return anything. Why??

Replies are listed 'Best First'.
Re^3: Windows Net Use
by hdb (Monsignor) on Mar 28, 2013 at 09:51 UTC

    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; }

      @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...

Re^3: Windows Net Use
by 7stud (Deacon) on Mar 28, 2013 at 09:45 UTC
    \\\\10.81.253.140\\IPC\$
    \\\\10.81.253.140\\IPC$   
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025911]
help
Chatterbox?
[1nickt]: watcha marto
[Discipulus]: good morning marto, 1nickt for you the sky is still black, no?
[Corion]: Hi all ;)
[1nickt]: just turning grey
[virtualsue]: likely to be grey here all day judging by the forecast
[1nickt]: The deer are in the back garden looking for corn left over from yesterday; the birds are not yet making a commotion. There is frost on the ground.
[1nickt]: virtualsue how's the retatching going?
[1nickt]: rethatching

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-11-21 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (297 votes). Check out past polls.

    Notices?