WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DOS

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Capture DOS Window Output 1


Dos Program output capture example 1

Dos Program output capture example 2

; This UDF function executes a DOS command and returns the
; sysout, syserror and exitcode information from the DOS
; program as a 3 element array

; Elements   Contents
;    0          ErrorLevel
;    1          StdOut
;    2          StdError

;Note: No way yet known to hide the DOS window from appearing on the screen
;except to perhaps have a "Keep on top" conver screen 
;(i.e. BoxesUp and other box functions + IntControl(54,1,0,0,0)



#DefineFunction CaptureDosOutput(DosCommand)
   
   DataArray=ArrDimension(3)               ;Allocate return array
   ArrInitialize(DataArray,"")             ;initialize to all null strings
   oShell = ObjectOpen("WScript.Shell")    ;open shell object
   oScriptExec = oShell.Exec(DosCommand)   ;run the command

   ;Open output objects
   oStdOut = oScriptExec.StdOut
   oStdErr = oScriptExec.StdErr

   While (oScriptExec.Status==0)           ;wait for completion

      ;Caputure StdOut data
      oStdOut = oScriptExec.StdOut
      While ! oStdOut.AtEndOfStream
         strLine = oStdOut.ReadLine
         DataArray[1] = StrCat(DataArray[1],strLine,@CRLF) 
      EndWhile
   
      ;Capture StdErr data
      oStdErr = oScriptExec.StdErr
      While ! oStdErr.AtEndOfStream
         strLine = oStdErr.ReadLine
         DataArray[2] = StrCat(DataArray[2],strLine,@CRLF) 
      EndWhile
   
      TimeDelay(0.1)
   EndWhile

   ;Get remainder of data, if any

      ;Caputure StdOut data
      oStdOut = oScriptExec.StdOut
      While ! oStdOut.AtEndOfStream
         strLine = oStdOut.ReadLine
         DataArray[1] = StrCat(DataArray[1],strLine,@CRLF) 
      EndWhile
   
      ;Capture StdErr data
      oStdErr = oScriptExec.StdErr
      While ! oStdErr.AtEndOfStream
         strLine = oStdErr.ReadLine
         DataArray[2] = StrCat(DataArray[2],strLine,@CRLF) 
      EndWhile


   DataArray[0]=oScriptExec.ExitCode         ;save errorlevel/exit code

   ;Close handles that were opened
   ObjectClose(oStdOut)
   ObjectClose(oStdErr)
   ObjectClose(oScriptExec)
   ObjectClose(oShell)

   ;Return the array
   Return(DataArray)

#EndFunction



DirChange("c:\windows")
;CaptureArray=CaptureDosOutput("ipconfig.exe /all")       ; for normal DOS executables
CaptureArray=CaptureDosOutput("cmd.exe /c dir *.*")      ; for built-in dos commands 
ClipPut(CaptureArray[1])
Pause(StrCat("Exit code: ",CaptureArray[0]),CaptureArray[1])
If CaptureArray[0] !=0 Then Pause("SysErr info",CaptureArray[2])




;Vol
;Displays the disk volume label and serial number, if they exist. A serial number is displayed for a disk 
;formatted with MS-DOS version 4.0 or later.
cmd = 'cmd /c vol c:'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Ver
;Displays the Windows XP version number.
cmd = 'cmd /c ver'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )



;Tree
;Graphically displays the directory structure of a path or of the disk in a drive.
DirChange(DirWindows(0))
cmd = 'cmd /c tree /a'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Tracert
;Determines the path taken to a destination by sending Internet Control Pause Protocol (ICMP) Echo Request
;Pauses to the destination with incrementally increasing Time to Live (TTL) field values. The path displayed 
;is the list of near-side router interfaces of the routers in the path between a source host and a destination. 
;The near-side interface is the interface of the router that is closest to the sending host in the path. 
cmd = 'tracert www.winbatch.com'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )



;Tasklist
;Displays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer.
cmd = 'Tasklist'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )



;Systeminfo
;Displays detailed configuration information about a computer and its operating system, including operating 
;system configuration, security information, product ID, and hardware properties, such as RAM, disk space, and network cards.
cmd = 'systeminfo'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Schtasks
;Schedules commands and programs to run periodically or at a specific time. Adds and removes tasks from the schedule, 
;starts and stops tasks on demand, and displays and changes scheduled tasks.
;Displays all tasks scheduled to run on the computer, including those scheduled by other users.
cmd = 'Schtasks'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Route
;Displays and modifies the entries in the local IP routing table. 
;To display the entire contents of the IP routing table, type:
cmd = 'route print'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Prnport.vbs
;Creates, deletes, and lists standard TCP/IP printer ports, in addition to displaying and changing port configuration.
DirChange("C:\WINDOWS\system32\")
cmd = '"cscript" "Prnport.vbs" -l'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Prnmngr.vbs
;Adds, deletes, and lists printers or printer connections, in addition to setting and displaying the default printer. 
;Used without parameters, prnmngr.vbs displays command-line help for the prnmngr.vbs command.
;To list all of the printers for a computer
DirChange("C:\WINDOWS\system32\")
cmd = '"cscript" "prnmngr.vbs" -l'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Prnjobs.vbs
;Pauses, resumes, cancels, and lists print jobs. 
;To list the print jobs in a print queue
DirChange("C:\WINDOWS\system32\")
cmd = '"cscript" "prnjobs.vbs" -l'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Prndrvr.vbs
;Adds, deletes, and lists printer drivers. 
;To list the printer drivers on a computer
DirChange("C:\WINDOWS\system32\")
cmd = '"cscript" "prndrvr.vbs" -l'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Prncnfg.vbs
;Configures or displays configuration information about a printer. Used without parameters, prncnfg.vbs 
;displays command-line help for the prncnfg.vbs command. 
;To display configuration information about a printer
If FileLocate("WWPRT34i.DLL") != ""
   AddExtender("WWPRT34i.DLL")
   defprt = pGetDefPrtInf(1)
   DirChange("C:\WINDOWS\system32\")
   cmd = StrCat('"cscript" "prncnfg.vbs" -g -p "',defprt,'"')
   outarray = CaptureDosOutput(cmd)
   Pause(StrCat(cmd," - STDOUT"), outarray[1] )
EndIf


;Nslookup
;Displays information that you can use to diagnose Domain Name System (DNS) infrastructure. Before using 
;this tool, you should be familiar with how DNS works. The Nslookup command-line tool is available only if 
;you have installed the TCP/IP protocol.
cmd = "Nslookup ls"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Netstat
;Displays active TCP connections, ports on which the computer is listening, Ethernet statistics, 
;the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics 
;(for the IPv6, ICMPv6, TCP over IPv6, and UDP over IPv6 protocols). Used without parameters, netstat 
;displays active TCP connections.

;Displays all active TCP connections and the TCP and UDP ports on which the computer is listening. 
cmd = "Netstat -a"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Displays Ethernet statistics, such as the number of bytes and packets sent and received.
cmd = "Netstat -e"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

 
;Displays active TCP connections, however, addresses and port numbers are expressed numerically and 
;no attempt is made to determine names. 
cmd = "Netstat -n"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Displays the contents of the IP routing table. This is equivalent to the route print command.
cmd = "Netstat -r"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )



;Ipxroute
;To display the network segments that the workstation is attached to, the workstation node address, 
;and frame type being used
cmd = "ipxroute config"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Net statistics
;Displays the statistics log for the local Workstation or Server service, or the running services for which 
;statistics are available. Used without parameters, net statistics lists the running services for which 
;statistics are available.
cmd = "cmd.exe /c net statistics workstation"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Date
;Displays the current system date setting. Used without parameters, date displays the current system date 
;setting and prompts you to type a new date.
cmd = "cmd.exe /c date /t"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Net view
;Displays a list of domains, computers, or resources that are being shared by the specified computer. 
;Used without parameters, net view displays a list of computers in your current domain.
cmd = "cmd.exe /c net view"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Ipconfig
;Displays all current TCP/IP network configuration values and refreshes Dynamic Host Configuration Protocol 
;(DHCP) and Domain Name System (DNS) settings. Used without parameters, ipconfig displays the IP address, 
;subnet mask, and default gateway for all adapters.
cmd = "ipconfig /all"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;nbtstat
;To display the NetBIOS name table of the local computer
cmd = 'nbtstat -n'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )


;Getmac
;Returns the media access control (MAC) address and list of network protocols associated with each address for all network 
;cards in each computer, either locally or across a network. 
cmd = 'Getmac'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;FC - File Compare
;To make an ASCII comparison of two text files that are named Monthly.rpt and Sales.rpt and display the results in abbreviated format, 
;  fc /a monthly.rpt sales.rpt
;To make a binary comparison of two batch files named Profits.bat and Earnings.bat, type:
;  fc /b profits.bat earnings.bat
;DirChange("C:\temp\data\")
;cmd = 'fc /a C:\Temp\Data\test.txt C:\Temp\Data\test2.txt'
;outarray = CaptureDosOutput(cmd)
;Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Eventquery
;Lists the events and event properties from one or more event logs.
DirChange("C:\WINDOWS\system32\")
cmd = '"cscript.exe" eventquery.vbs /l application'
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Driverquery
;Displays a list of all installed device drivers and their properties.
cmd = "driverquery"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )

;Ping
;Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Pause Protocol (ICMP) 
;Echo Request Pauses. The receipt of corresponding Echo Reply Pauses are displayed, along with round-trip times. 
;Ping is the primary TCP/IP command used to troubleshoot connectivity, reachability, and name resolution. Used 
;without parameters, ping displays help.
cmd = "ping www.winbatch.com"
outarray = CaptureDosOutput(cmd)
Pause(StrCat(cmd," - STDOUT"), outarray[1] )





Article ID:   W15938
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38