#162426 - 2006-05-24 05:34 PM
Using WshPipe output
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
I have a VBScript that will tell me what server a user is logged into, in the form of UserName:ServerName. I want to use that information in a script, so I setup the following:
Code:
$rc=split("WshPipe("cscript //nologo C:\WhereIs.wsf operez",1)",":") ? $rc(0) ? $rc(1)
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 $Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll If Not $NoEcho $Output Endif $WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10)) Exit($oExec.ExitCode) EndFunction
I am getting an “Error in expression: this type of array not supported in expressions.! Line: 2” error message. It’s been awhile since I used kix, but what am I doing wrong?
|
|
Top
|
|
|
|
#162428 - 2006-05-24 06:00 PM
Re: Using WshPipe output
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
The script output is UserName:ServerName and I want to split the results at the colon onto two elements in the array, the first is the UserName and the second is the ServerName.
For the purpose of just testing my logic, I was outputting the results of each element to the screen.
|
|
Top
|
|
|
|
#162429 - 2006-05-24 06:21 PM
Re: Using WshPipe output
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$return = WshPipe("cscript //nologo C:\WhereIs.wsf operez",1) for each $line in $return if instr($line,':') $rc=split($line,":") ? $rc(0) ? $rc(1) else ? 'no : in line -> ' + $line endif next
|
|
Top
|
|
|
|
#162432 - 2006-05-24 09:11 PM
Re: Using WshPipe output
|
operez
Getting the hang of it
Registered: 2003-08-08
Posts: 75
|
Les,
I had may last cup of coffee almost 6 hours ago and I’ve had a big lunch, so forgive me if I don’t understand your question. Because, the output from my VBScript is the user name and the server name, separated by a colon. Wouldn’t that also be the output of WshPipe function?
I don’t get to script much and I don’t get out very often, but you’ve made me see the error in my ways. I now realize that I was trying to split an array, when the split command only works on strings.
Radimus,
I had to change Code:
? $rc(0) ? $rc(1)
to Code:
? $rc[0] ? $rc[1]
to make this script work. I really appreciate your help.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|