Page 1 of 1 1
Topic Options
#109096 - 2003-11-27 01:27 PM How to split a string and captures part of that?
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Hi,

Im trying to use Instr and Split command to capture the retured value of "Name" in the bellow "nbtstat -c" output.
I cannot make it work Anybody knows how to do???

Name Type Host Address Life [sec]
------------------------------------------------------------
CyrusA <20> UNIQUE 192.168.0.33 502

LOTR1 <03> UNIQUE 192.168.0.33 600

Simply i need $UserID = CyrusA and $Computer = LOTR1

note there is blank space between each string.

BR
/C


Edited by Cyrus (2003-11-27 02:02 PM)
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#109097 - 2003-11-27 02:00 PM Re: How to split a string and captures part of that?
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Code:
 break on

$cmd='cmd /c nbtstat -c|find "<"'
$return=wshpipe($cmd,1)
for each $line in $return
if trim($line) > ' '
? $line
$computer = trim(split($line,'<')[0])
$ip = trim(left(trim(split($line,'UNIQUE')[1]),16))
? $computer
? $ip
?
endif
next

;********************************************************************************************
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
While Not $oExec.Status Loop
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split($Output,CHR(10))
Exit($oExec.ExitCode)
EndFunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#109098 - 2003-11-27 02:03 PM Re: How to split a string and captures part of that?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
There can be more than one entry in these results, but the easiest way to get the first part of the line is:

Code:
$name = split($line, chr(32))[0]  

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#109099 - 2003-11-27 02:08 PM Re: How to split a string and captures part of that?
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
The Computer name in secound row "LOTR1" - Can I get that value in the same script?

Thanx
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#109100 - 2003-11-27 02:23 PM Re: How to split a string and captures part of that?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Rad's previous post would handle multiple lines.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 131 anonymous users online.
Newest Members
dimi575, Drecksnacken, Nlill, webtools321, multiman
17734 Registered Users

Generated in 0.03 seconds in which 0.012 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org