Page 2 of 2 <12
Topic Options
#86096 - 2002-06-13 11:11 PM Re: WSH Shell Piper
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I agree.. this looks pretty neat! [Smile]

Brian

Top
#86097 - 2002-06-14 09:08 AM Re: WSH Shell Piper
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Maybe something like this?
code:
Function WshPipe($Command,optional $Ignore)
Dim $Exit,$Output,$i,$Array[4096]

$WshShell=CreateObject("WScript.Shell")
$oExec=$WshShell.Exec($Command)
$i=0 $Limit=UBound($Array)

While $Exit<>1
Dim $Output
$Output=ReadAll($oExec)

If $Output=-1
If $oExec.Status=1
$Exit=1
EndIf
Else
If $Ignore And InStr($Output,'File not found')<>0?
$Output=''
EndIf

If $Output
$Array[$i]=$Output
If $i=$Limit
$Limit=$Limit*2
Redim Preserve $Array[$Limit]
EndIf
$i=$i+1
EndIf
EndIf
Loop

If $i>0
Redim Preserve $Array[$i-1]
$Pipe=$Array
EndIf

Exit($oExec.ExitCode)
EndFunction


Function ReadAll($oExec)
If Not $oExec.StdOut.AtEndOfStream
$ReadAll=$oExec.StdOut.ReadAll
Exit
endif
If Not $oExec.StdErr.AtEndOfStream
$ReadAll=$oExec.StdErr.ReadAll
Exit
endif
$ReadAll=-1
EndFunction

However, i did not add the suggestion of the environment (you could add it to the command..). Also, this function returns an array like the Pipe() UDF did.
_________________________
Kind regards,

Top
#86098 - 2002-06-14 04:23 PM Re: WSH Shell Piper
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Schuliebug, is your intention to have each line of output in it's own array element? If you check the actual number of items in your array for a successful "dir" you'll have just one item. An unsuccessful "dir" will have two items, the results & the "file not found" message.

Anyway, I have a fix for it if that is your intention and will post a UDF soon.

[ 14 June 2002, 16:27: Message edited by: Chris S. ]

Top
#86099 - 2002-06-14 06:42 PM Re: WSH Shell Piper
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
technically, (if you look at my sample) the udf returns a string that if you split() on chr(10) you will get an array from that (if necessary)

What I would like is a to combine stdout and stderr into the return... or use stderr to set the @error and @serror values

THAT would be perfect.

I would like to be able to pass optionally the environment size into the UDF, as many commands do not need it, but some do... therefore ignore it if not necesary, but pass it if you do.

Once this works, there are many useful Find() functions to be able to parse the output... much easier that the cmd line version... but this is outside the scope of this UDF
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 2141 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.169 seconds in which 0.143 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