I’m trying to execute a command via ssh, take only the first part of the returned command, and set it as a variable to be used. I’m attempting to use RegExp and because I only need the first 4 digits, I use the pattern code “^\d{1,4}” I can successfully get the entire return via this code;
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec ("ssh -un -pw command")
Do Until oExec.StdOut.AtEndOfStream
ID = oExec.StdOut.ReadLine
Loop
WScript.Echo ID
But Now when I try to use RegExp and echo to see if I’m getting what I want I get a “Type Mismatch” error
Set RegExp = New RegExp
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec ("ssh -un -pw command")
RegExp.Pattern = "^\d{1,4}"
Do Until oExec.StdOut.AtEndOfStream
ID = oExec.StdOut.ReadLine
WScript.Echo RegExp.execute(ID)
Loop
If anyone has any incite on what’s wrong with the code please let me know. If you know of any alternative I’d appreciate it. Using a shell script I can get what I’m looking for but I need to run this VBS with windows. Here’s the Shell script if anyone can translate it to VBS.
.............for i in `command | sed ‘1d’ | awk ‘{print $1}’`..............
Appreciate any help in advance… Been racking my brain on this one for a while and getting burnt out.
You can’t .Echo an object like the match collection you get from .Execute; access the .Value of its first item: