scripting@wanadoo.nl




Pipe()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
12 June 2002 Pipe()
AuthorShawn & LLigetfa,Bryce,AJH
Action Submits a shell command and redirects output to an array.
SyntaxPipe ("command") 
Parameters
  • command (Required / String) A DOS command 
  • RemarksOn 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. 
    ReturnsAn array containing the output text of the DOS command. @ERROR is set to the return value of the SHELL command (winnt). 
    DependenciesNone. 
    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 -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter