- A Dll file designed for retrieving output from console based applications and saving the output in a variable and/or redirecting to a control without displaying the console window or creating/using temporary files.
Latest release:
CMDret 4d Beta - Download (cmdret.dll, cmdstub.exe, several test scripts)
- updated all functions for Windows 2000 compatibility (hopefully)
- This version contains the following functions:
RunRedirect(CMDin)
RunInControl(CMDin, ControlHwnd)
RunReturn(CMDin, CMDout)
RunWEx(CMDin, WorkingDir, CMDin, CMDout, CMDerr)
RunWCB(CMDin, CallbackAddress) - callback - (PID, NumberOfCharsInOutput, Output, FutureUse)
Previous Releases:
CMDret - v3.2.1 (DLL version)
CMDret v3.x is a .DLL file (Freeware) that has been designed to return the output from a console program to a variable (rather than redirect to a textbox like the command line version). Version 3.1 (or greater) now includes a function that has the ability to output to a control and should be more stable than the command line version. Please keep in mind that CMDret is currently a beta realease. Any feedback would be greatly appreciated .
Win9.x users
Note: only 32 bit console applications will currently work with the this dll version of CMDret (v3.1.2 or lower). Calls that require command.com will likely not produce any output and may crash. To avoid this I have included a file named "cmdstub.exe" with the download (in the Win9x folder in the zip file). This file should be used when calling 16 bit console applications to enable returning output. Example: cmdstub.exe command.com /C set
Updated: March 15, 2008 - version 3.2.1
- modified: the methods used in the functions to detect when a console program has finished executing to improve stability, reliability and efficiency (hopefully)
- modified required parameters for the RunInControl function
- Added: sample scripts
Updated: June 1, 2005 - version 3.1.2
- Added cmdstub.exe to the download to support 16 bit console applications
Updated: May 30, 2005 - version 3.1.2
- Tweaked the RunReturn function
- Added another function to the dll (RunWEx) to allow StdInput, StdOutput, StdError
Updated: May 24, 2005 - version 3.1.1
- Added another function to the dll (RunReturn) to allow returning output to a variable. This function does not require the additional LoadLibrary, lstrcpyA, and FreeLibrary calls.
Current functions:
RunReturn(CMD, StrOut)
- CMD - the console program/command to execute (str)
- StrOut - the variable used to store the output (str)
= If the function fails, the return value is zero
RunWEx(CMD, CMDdir, CMDin, CMDout, CMDerr)
- CMD - the console program/command to execute (str)
- CMDdir - Future Use (working directory - not currently functional) (str)
- CMDin - StdInput String (str)
- CMDout - the variable used to store StdOutput output (str)
- CMDerr - the variable used to store StdError output (str)
= If the function fails, the return value is zero
RunRedirect(CMD)
- Where CMD is the console program/command to execute (str)
RunInControl(CMD, WinHandle, CtrlClass, CtrlInstance)
- CMD should be the console program/command to execute (str)
- CtrlHWND should be the handle to the control to stream into
= If the function fails, the return value is zero
Download the latest version (DLL Version 3.2.1)
Download (DLL Version 3.1.2)
Alternate Download for version 3.1.2
BCX Source (version 3.1.2) - not currently available...
Notes:
- To check which version you currently have - right click on cmdret.dll, select Properties, and click the Version tab
- When trying to retrieve a directory listing be sure to specify a directory after a 'DIR' command. ( COMSPEC " /C Dir c:\" )
Sample Code:
; CMDret DLL version 3.1.1 (or greater) required ret1 := CMDret(COMSPEC " /C set") MsgBox, %ret1% CMDret(CMD) { VarSetCapacity(StrOut, 10000) RetVal := DllCall("cmdret.dll\RunReturn", "str", CMD, "str", StrOut) Return, %StrOut% }
; CMDret (DLL version 3.0 or greater required) examples CMD := COMSPEC " /C set" VarSetCapacity(StrOut, 1000) hModule := DllCall("LoadLibrary", "str", "cmdret.dll","UInt") DllCall("lstrcpyA", "str", StrOut, "int", DllCall("cmdret.dll\RunRedirect", "str", CMD)) DllCall("FreeLibrary", "UInt", hModule) MsgBox %StrOut% CMD := "ipconfig /all" VarSetCapacity(StrOut, 1000) hModule := DllCall("LoadLibrary", "str", "cmdret.dll","UInt") DllCall("lstrcpyA", "str", StrOut, "int", DllCall("cmdret.dll\RunRedirect", "str", CMD)) DllCall("FreeLibrary", "UInt", hModule) MsgBox %StrOut%
Streaming Example:
; CMDret DLL version 3.1 (or greater) required Gui, Add, Edit, x6 y10 w460 h360 +HScroll Gui, Show, x398 y110 h377 w477, CMDret - DLL version - Streaming Test App CMD = ping 127.0.0.1 OutputWindow := WinExist("CMDret - DLL version - Streaming Test App") StrOut := DllCall("cmdret.dll\RunInControl", "str", CMD, "Uint", OutputWindow, "str", "Edit", "int", "1") Return GuiClose: ExitApp