XP is just a number PerlMonks

### Re: Windows Net Use

by hdb (Parson)
 on Mar 28, 2013 at 08:15 UTC ( #1025887=note: print w/ replies, xml ) Need Help??

in reply to Windows Net Use

You can avoid splitting alltogether if you search for your share in the output of net use and then return the first word of that line.

```use strict;
my \$inputDirectory = '"\\\\10.81.253.70\\file data\\query files"';
# need to dublicate each \ in string
\$inputDirectory =~ s|\\|\\\\|g;
my @lines = `net use`;
foreach my \$line ( @lines ) {
next unless \$line =~ m|\$inputDirectory|;
\$line =~ /(^\S+)/;
print \$1;
}

This also overcomes the issue that the output of net use is sometimes split into two lines when it is too long. The output of net use sometime returns no status as well, which might be a problem or not.

Comment on Re: Windows Net Use
Re^2: Windows Net Use
by Anonymous Monk on Mar 28, 2013 at 09:05 UTC

Thnks hdb .. But when i input the directory as

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

It does not return anything. Why??

```\\\\10.81.253.140\\IPC\\$
\\\\10.81.253.140\\IPC\$
```

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)

Create A New User
Node Status?
node history
Node Type: note [id://1025887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-04-18 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?