User Defined Commands

 

The WinBatch Console supports a special form of user-defined procedure called a user-defined command (UDC) .

A #DefineCommand user-defined procedure is similar to a WIL user-defined subroutine because it has the same 'caller' scope as #DefineSubroutine user-defined subroutine . However, UDC's can only be called from WinBatch Console.  Calls are ignored in scripts executed with regular WinBatch. The #DefineCommand syntax also differs because it does not need opening and closing parentheses and it uses spaces instead of comas as parameter separators. Also note that parameters can be any legal WIL expression but not  WIL statements like a structured if, immediate if, any loop structures, an exit, or a goto.

 

(WinBatch Console only)

A #DefineCommand UDP is defined as follows:

 

#DefineCommand functname param1 param2 param3 param4 …param16

<code> 

Return retval 

#EndCommand

 

Example:
   #DefineCommand ls _path
   
      ; Default to current directory.
      If _path=='' Then tmp=DirGet():'*.*'
      Else tmp=_path
   
      delim=IntControl(29,@lf,0,0,0)
      files=FileItemize(tmp)
      IntControl(29,delim,0,0,0)
     Cout files
  
     Return 1
  #EndCommand
                

 

DefineCommand Image

 

See Also:

WinBatch Console

 

WARNING: Use at your own risk. The variables used within a #DefineCommand have 'caller' scope, which means the Variables are shared with the calling routine. We suggest using a special naming convention on the variables inside a #DefineCommand. The Drop and DropWild functions, can be used to dispose of any unwanted variables at the end of the routine.

UDC Special Notes:

  • If you call GoSub from within a User Defined Command, the 'label' must be defined within the User Defined Function

  • If you want to debug the User Defined Procedure, then the debug function (Debug or Debugtrace), must be defined within the User Defined Command

  • To include cancel/error handling in a User Defined Command, then IntControl 72 / IntControl 73 must either:

    1) Be defined within the
    UDC. The :CANCEL / :WBERRORHANDLER label must also be contained within the UDC
    2) Or
    p1 must be the value of 3 and p3 must specify the name of the cancel / error handler UDF.

  • Maximum number of UDF/UDS/UDC's allowed is 512

 

 

 

 

Cin

Cout

Multiline Mode

Console Keyboard Shortcuts