|
|
|
| 12 June 2002 | Pipe() |
| Author | Shawn & LLigetfa,Bryce,AJH |
| Action | Submits a shell command and redirects output to an array. |
| Syntax | Pipe ("command") |
| Parameters | |
| Remarks | On WinNT, stderr is redirected to the NUL device (discarded). This function uses File Handle #10 - please change if conflict arises. Function creates a temporary file in %TEMP% called PIPE.TMP - deleted after use. Empty (null) lines are skipped (not included) in the output array. Piping between processes (in the command string) is supported. NOTE: Do not specify redirection of output in command string. |
| Returns | An array containing the output text of the DOS command. @ERROR is set to the return value of the SHELL command (winnt). |
| Dependencies | None. |
| Examples |
$array = Pipe("net users") ; load output of net users into an array
$array = Pipe("dir c:\*.ini /s /b") ; load a listing of all ini files into an array
$array = Pipe("type config.txt") ; load the contents of a text file into an array
$ipconfig = Pipe('ipconfig /all | find "Server"')
for each $line in $ipconfig
? $line
next
|
| Source |
FUNCTION Pipe ($command)
DIM $i,$error,$line
DIM $array[255]
DIM $redim $redim = UBound($array)
DIM $tempfile $tempfile = "%temp%\pipe.tmp"
IF Exist("$tempfile")
DEL("$tempfile")
ENDIF
IF (@inwin = 2) ; win9x
SHELL '%comspec% /c $command >"$tempfile"'
ELSE ; winnt
SHELL '%comspec% /c $command >"$tempfile" 2>nul'
ENDIF
$error=@error
IF Open(10,"$tempfile") = 0
$i=0
$line = ReadLine(10)
WHILE NOT @error
IF $line
$array[$i] = $line
IF $i = $redim
$redim=$redim*2
REDIM PRESERVE $array[$redim]
ENDIF
$i=$i+1
ENDIF
$line = ReadLine(10)
LOOP
$=Close(10)
DEL "$tempfile"
IF ($i > 0)
REDIM PRESERVE $array[$i-1]
$pipe=$array
ELSE
$pipe = 0
ENDIF
EXIT $error
ELSE
$pipe = 0
EXIT @error
ENDIF
ENDFUNCTION ; - Pipe -
|
|
|
|