;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       kfExec() 
;; 
;;ACTION         Executes a command and returns STDOUT/STDERR via Kixforms.DLL 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.1 - 2020/04/23 
;; 
;;HISTORY        1.0 - 2020/01/04 - Initial Release 
;;               1.1 - 2020/04/23 - Improve error checking 
;; 
;;SYNTAX         kfExec(Command [, What] [, Pointer]) 
;; 
;;PARAMETERS     Command - REQUIRED - description 
;; 
;;               What    - OPTIONAL - What to return: 
;;                              0 = Nothing 
;;                              1 = STDOUT 
;;                              2 = STDERR 
;;                              3 = STDOUT/STDERR (default) 
;; 
;;               Pointer - OPTIONAL - Use an existing KF Object Reference Pointer 
;; 
;;REMARKS        The KF object should be instantiated in the main program if this 
;;               function will be called multiple times. 
;; 
;;RETURNS        The output of the command based on what was requested. 
;; 
;;DEPENDENCIES   Kixforms.DLL 
;; 
;;TESTED WITH    W2K8, W2K12, W2K16 
;; 
;;EXAMPLES        
; 
Function kfExec($_Cmd, Optional $_What, $_Pointer)
 
  Dim $_oSys                                                    ; SYSTEM object pointer 
  Dim $_Data                                                    ; results from exec 
  Dim $_aData                                                   ; Data array 
 
  If Not $_What
    $_What = 3
  EndIf
 
  If VarType($_Pointer) = 9
    $_oSys = $_Pointer
  Else
    $_oSys = CreateObject('Kixtart.System')
    If @ERROR
      Exit @ERROR
    EndIf
  EndIf
  
  $_Data = $_oSys.Shell($_Cmd, 0, $_What)
  If @ERROR
    Exit @ERROR
  EndIf
  
  $_aData = Split($_Data, @CRLF)
  
  If VarType($_Pointer) <> 9                                    ; close the object if we own it 
    $_oSys = 0
  EndIf
  
  $kfExec = $_aData
 
  Exit 0
 
EndFunction