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

Hi there im writing a pretty simple program (until now) that will use the net command on 98 boxes to map a drive with a statement like this "system("NET USE h: \\\\jafs\\$me");" the thing is that i would rather just grab the username from a net config statement instead of prompting the user so overall this is what im trying to do..

use strict;
system("NET CONFIG")

"get $me from username output of net config"

system("NET USE h: \\\\jafs\\$me");


btw the output of the net config command looks like this on a 98 box:(underscores for spacing);
C:\perl\bin>net config
Computer name__________________\\LIB211406
User name______________________Bjones
Workgroup_____________________workgroup
workstation root directory__________C:\Windows

Software version_______________4.10.1998
Redirector version_____________4.00
The command was completed successfully"

Your humble perl savant,
N1n3r

Replies are listed 'Best First'.
Re: Formatting Output from system commands
by mce (Curate) on Oct 23, 2002 at 14:11 UTC
    Hi,

    What you can do with Win32 and Win32::NetResource and Win32::Lanman. is pretty much all you want. Don't spend time on writing perl as a wrapper interface to cmd, but dig into the modules. (they all come with ActiveState)

    Just a hint:

    Win32::Login(); # gives you the loging name Win32::NetResource::AddConnection() # add connection

    I hope this helps
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium
Re: Formatting Output from system commands
by tommyw (Hermit) on Oct 23, 2002 at 14:04 UTC

    How about (untested)

    my ($me)=`net config`=~/^User name\s+(.*)$/m;
    to run net config, search it for the string User name, and grab the stuff from the other end of that line (which is put back into your variable). (The m modifier makes ^ and $ match the start and end of lines, rather than the start and end of strings.)

    --
    Tommy
    Too stupid to live.
    Too stubborn to die.

Re: Formatting Output from system commands
by nothingmuch (Priest) on Oct 23, 2002 at 14:29 UTC
    The perlpack pod file, in the 5.8 standard distribution offers an interesting alternative, specifically fur such aligned data.

    The approach is to use ($field,$value) = unpack("A[] A*",$line) for each of the lines. Inside the brackets place the running length of the spaces, and the text in the field, and the A packing template automatically strips the trailing spaces. It may be a bit more efficient than the above mentioned regexp, but i make note of mainly just because TMTOWTDI.

    -nuffin
    zz zZ Z Z #!perl