scripting@wanadoo.nl




Write()

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
23 April 2002 Write()
AuthorW.M. Hinsch (New Mexico Mark)
Action Send a string to one or more destinations.
SyntaxWrite (TextStr, CtrlInt, DestStr) 
Parameters
  • TextStr (Required / String) Text string to be written.
  • CtrlInt (Optional / Numeric) Integer sum of options. Default or 0 is console-only output.
  • DestStr (Optional / String) A string with either the workstation name or user name to supply to Net Send. If this is specified, the Net Send (= bits 128) option is automatically flagged. I suppose this would support the optional switches for Net Send as well, but I haven't tested that behavior. 
  • RemarksSimple, yet it allows for elegant scripts with flexible output.
    The advantages to using Write() rather than other methods are:
    1. Flexibility. A string may be directed to up to five destinations with one command.
    2. Ease of use. The CRLF is automatically appended to the WriteLine() function. Date and Time can be prepended to the string as well.
    3. Nothing is returned, so there is no need to check error codes.
    4. Any error generated within Write() by WriteLine, LogEvent(), or "Net Send" will cause the function to automatically write to the console unless that is suppressed. 
    ReturnsNothing. 
    DependenciesThe file handle to write to must already be open for writing. LogEvent requires NT/2K/XP. 
    Examples
    Write('Default to console output.')
    $RC = Open(1,'%temp%\test.txt',5) ; Open a log for output
    Write('Write to log only in log format .',1+1024)
    Write('Write to Log and Console in log format.',65+1024)
    $RC = Close(1) ; Close the log
    Write('Forced console output and failover.',1+16)
    Write('Failover to console output only... file 1 not open.',1)
    Write('No log open, but console failover suppressed.',1+512)
    Write('Specified write to console in log format.',16+1024)
    Write('Write to MessageBox and console.',16+32)
    Write('Write to EventLog and console.',16+64)
    Write('Write to Messenger service and console.',16+128)
    Write('Write to MessageBox and Messenger service with specified workstation.',128+32,@WKSTA)
    $Text = 'Potential conflict - '+@crlf+'  Force console output AND suppress console failover. Console output wins.'
    Write($Text,16+512)
    
    ; Console Output (Example)
    
    ;Default to console output.
    ;2002/04/18 14:25:22 - Forced console output and failover.
    ;Failover to console output only... file 1 not open.
    ;2002/04/18 14:25:22 - Specified write to console in log format.
    ;Write to MessageBox and console.
    ;Write to EventLog and console.
    ;Write to Messenger service and console.
    ;2002/04/18 14:25:26 - Potential conflict -
       Force console output AND suppress console failover. Console output wins.
    
     
    Source
    FUNCTION Write ($stext, OPTIONAL $idest, OPTIONAL $snetdest)
      ; Summary      - Write string to one or more destinations.
      ; $sText       - Text string
      ; $iDest       - Integer sum of options. Default or 0 is console-only output.
      ; $sNetDest    - Destination for NetSend (workstation or user name). Default
      ;                is @wksta. If specified, bit 128 is flagged automatically.
      ; Bit(s)  Dec.   Specifies Destination(s)...
      ; 0-3   1...10 = File number (must be opened for write already - adds CRLF)
      ;   4       16 = Console (No formatting done. CRLF's must be imbedded)
      ;   5       32 = MessageBox (Title="Message...", Default style and timeout)
      ;   6       64 = EventLog (Type=Info, ID=1, Target=local, Source=Kix32)
      ;   7      128 = Messenger service (Net Send to @WKSTA)
      ;   8      256 = Reserved
      ; Bit(s)  Dec.   Specifies Behavior(s)...
      ;   9      512 = Suppress default failover to console output.
      ;  10     1024 = Prepend "Date^Time^-^" before text for log format.
      ; Dependencies:  LogEvent() requires NT/2K/XP
      ; Returns:       Nothing
    
      $stext=''+$stext
      $idest=0+$idest
      IF ($snetdest = '')
        $snetdest=@wksta
      ELSE
        $idest=$idest | 128
      ENDIF
      DIM $rc, $dmy
      IF $idest & 1024
        $stext='@DATE @TIME - '+$stext
      ENDIF
      IF (($idest & 15) - 11) < 0
        $rc=WriteLine(($idest & 15), $stext + @crlf)
      ENDIF
      IF $idest & 32
        $dmy=MessageBox($stext,"Message...",0)
      ENDIF
      IF $idest & 64
        $rc=LogEvent(4,1,$stext)
      ENDIF
      IF $idest & 128
        SHELL '%comspec% /c net send "$sNetDest" "$sText" > nul'
        $rc=@error
      ENDIF
      IF $idest & 16
        ? $stext
      ELSE
        IF (($idest = 0) OR $rc) AND (($idest & 512) = 0)
          ? $stext
        ENDIF
      ENDIF
    ENDFUNCTION ; - Write -
     
      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