CMDret - A utility designed to retrieve output from console for use with GUI apps.
DLL Version now available here :!:
Latest command line version 1.1 - March 25, 2005
Download Version 1.1 (Sample AHK scripts included)
Download Version 1.1 source (BCX, C)
CMDret AHK Usage:
RunWait, CMDret.exe "AHK Window Title" "p=myfile.exe" "optional - arguments" "Clear",, Hide
"AHK Window Title"
- Window Title of the AHK app that is to receive the console text
"p=myfile.exe"
- p= is required for AHK apps at this time. Replace
myfile.exe with the path/filename to be run.
"optional - arguments"
- Optional Arguments (file to open, switches, etc...)
"Clear"
- nc = don't clear contents of control first (Optional)
- default = clear first
Notes:
- The file path for p= will be converted to 8.3 format before executing
- A path/filename is not required after p= but path/filename(s) in "optional arguments" are not converted to 8.3 format.
- Single quotes may be used for paths that contain spaces in "optional - arguments"
- An Edit Control with CMD as text is currently a requirement when using this method but does not need to be visible
Generic Usage:
CMDret.exe "Window Title" "Edit Title" "Edit Class" "Window Class" "CMD to execute" "Optional - arguments" "Clear"
Window Title -> Window title of app to receive text
Edit Title -> Title of control to receive text
Edit Class -> ClassName of control to receive text
Window Class -> ClassName of window
CMD to execute -> Path/Name of the file to run (will be converted to 8.3 format)
Arguments -> Optional arguments
Clear -> Optional (nc = don't clear control's contents first)
Notes:
- Edit Title should NOT begin with p= (or P=)
- Single quotes may be used for paths that contain spaces in "Aguments"
- This syntax may be used for non-AHK apps or to send console text to a different app and/or control
version 1.1
- added option to output to an existing control without clearing the control's contents first
- added a couple more sample scripts
- source available
Known bugs:
- The included example cmdtst.ahk may not work correctly on Win 2k
Included Scripts
Since Hotstrings require Windows NT/2000/XP or beyond the included sample_1.1.ahk script will not work on Win9.x systems but may be modified to use hotkeys instead for Win9.x use.
CMDret - Capture Output from Console [CMD]
Started by
corrupt
, Jan 25 2005 08:20 AM
22 replies to this topic
#1
-
Posted 25 January 2005 - 08:20 AM
Another sample script that uses CMDret...
(watch for wordwrap...)
(watch for wordwrap...)
; --------------------------------------------------------------------------------------------- ; ; CMDret - Example - IP Tools ; ; 2005 Apps4Apps ; Http://www.Apps4Apps.filetap.com ; ; NO WARRANTY. USE IT AT YOUR OWN RISK. ; ; --------------------------------------------------------------------------------------------- ; #NoTrayIcon SetBatchLines, 5ms Gui, Add, Edit, x6 y7 w420 h300 +HScroll vTbox, Welcome. `n`nPlease view documentation for additional info on use of this script. Gui, Add, Button, x6 y317 w140 h20 gButton1, Ping Address Gui, Add, Button, x6 y337 w140 h20 gButton2, Tracert Address ; sample 1,2 Gui, Add, Button, x146 y317 w140 h20 gButton3, IPCONFIG (all) Gui, Add, Button, x146 y337 w140 h20 gButton4, IPCONFIG (simple) Gui, Add, Button, x286 y317 w140 h20 gButton5, IPCONFIG Release Gui, Add, Button, x286 y337 w140 h20 gButton6, IPCONFIG Renew Gui, Add, Edit, x0 y0 w100 h10 +HScroll -0x10000000 vmyvar , CMD ; Invisible Edit control Gui, Show, h366 w434, CMDret - Example - IP Tools menu, tray, Icon ; ----------------------------------------------------------- ; Added variables to minimize typing ;) ; RunCMD1 - AHK usage, RunCMD2 - Generic Usage ; tempCMD - temporary variable to store console text in. Added to reduce ; the chance of the Edit control's title changing (CMDret uses ; the control's title to find the control) ; ----------------------------------------------------------- RunCMD1 = CMDret.exe "CMDret - Example - IP Tools" RunCMD2 = CMDret.exe "CMDret - Example - IP Tools" "CMD" "Edit" "AutoHotkeyGUI" tempCMD = lastCMD = Return ; ----------------------------------------------------------- ; Ping Address ; ----------------------------------------------------------- Button1: ; ********************* InputBox, tracethis, Tracert, Address to Ping:,, 200, 120,,,,, %tracethis% if ErrorLevel = 1 { } else if tracethis = { } else { GuiControl,, Tbox, %lastCMD% ; clear Edit1 SetTimer, RefTxt, 250 RunWait, CMDret.exe "CMDret - Example - IP Tools" "p=" "ping %tracethis%",,Hide SetTimer, RefTxt, Off Gosub, RefTxt lastCMD= } Return ; ----------------------------------------------------------- ; Tracert Address ; ----------------------------------------------------------- Button2: InputBox, tracethis, Tracert, Address to Trace:,, 200, 120,,,,, %tracethis% if ErrorLevel = 1 { } else if tracethis = { } else { GuiControl,, Tbox, %lastCMD% ; clear Edit1 SetTimer, RefTxt, 250 RunWait, CMDret.exe "CMDret - Example - IP Tools" "p=" "TRACERT %tracethis%",,Hide SetTimer, RefTxt, Off Gosub, RefTxt lastCMD= } Return ; ----------------------------------------------------------- ; IPCONFIG /ALL ; ----------------------------------------------------------- Button3: GuiControl,,Tbox, RunWait, %RunCMD2% "%COMSPEC%" "/C IPCONFIG /ALL",, Hide GuiControlGet, tempCMD,,myvar GuiControl,,Tbox, IPCONFIG Info (all): `r`n`r`n%tempCMD% ; (2) Return ; ----------------------------------------------------------- ; IPCONFIG ; ----------------------------------------------------------- Button4: GuiControl,,Tbox, RunWait, %RunCMD2% "%COMSPEC%" "/C IPCONFIG",, Hide GuiControlGet, tempCMD,,myvar GuiControl,,Tbox, IPCONFIG INFO (simple): `r`n`r`n%tempCMD% ; (2, 2) Return ; ----------------------------------------------------------- ; IPCONFIG /release ; ----------------------------------------------------------- Button5: GuiControl,,Tbox, RunWait, %RunCMD2% "%COMSPEC%" "/C IPCONFIG /release",, Hide GuiControlGet, tempCMD,,myvar GuiControl,,Tbox, Results: `r`n`r`n%tempCMD% Return ; ----------------------------------------------------------- ; IPCONFIG /renew ; ----------------------------------------------------------- Button6: GuiControl,,Tbox, RunWait, %RunCMD2% "%COMSPEC%" "/C IPCONFIG /renew",, Hide GuiControlGet, tempCMD,,myvar GuiControl,,Tbox, Results: `r`n`r`n%tempCMD% Return ; ----------------------------------------------------------- ; Refresh ; ----------------------------------------------------------- RefTxt: GuiControlGet, tempCMD,,myvar if tempCMD = { } else { if lastCMD <> %tempCMD% { StringLen, lastLen, lastCMD StringTrimLeft, updCMD, tempCMD, %lastLen% ControlSend, Edit1, {CtrlDown}{END}{CTRLUP}, CMDret - Example - IP Tools Control, EditPaste, %updCMD%, Edit1, CMDret - Example - IP Tools ControlSend, Edit1, {CtrlDown}{END}{CTRLUP}, CMDret - Example - IP Tools lastCMD = %tempCMD% lastLen= } } Return ; ----------------------------------------------------------- GuiClose: ExitApp ; -----------------------------------------------------------
#2
-
Posted 22 March 2005 - 08:46 PM
Redirect to Notepad example using CMDret version 1.1:
#Persistent ; --------------------------------------------------------------------------------------------- ; ; CMDret 1.1 - Example ; ; - Redirect Output to Notepad ; - modified 22:47 EST, March 25, 2005 ; ; 2005 Apps4Apps ; Http://www.Apps4Apps.filetap.com ; ; NO WARRANTY. USE IT AT YOUR OWN RISK. ; ; --------------------------------------------------------------------------------------------- Run, Notepad Loop, %A_ScriptFullPath% Spath = %A_LoopFileShortPath% If Spath = Spath = %A_ScriptFullPath% RunCMD1 = CMDret.exe "Untitled - Notepad" "" "Edit" "Notepad" "" "%COMSPEC% /s /C ver" "nc" RunCMD2 = CMDret.exe "Untitled - Notepad" "" "Edit" "Notepad" "" "ping localhost" "nc" RunCMD3 = CMDret.exe "Untitled - Notepad" "" "Edit" "Notepad" "" "%COMSPEC% /s /C type %Spath%" Return ::winver:: RunWait, %RunCMD1%,,Hide Return ::pingit:: RunWait, %RunCMD2%,,Hide Return ::src:: RunWait, %A_ScriptDir%\%RunCMD3%,,Hide ; MsgBox, %RunCMD3% Return
#3
-
Posted 25 March 2005 - 09:44 PM
Excellent! This could lead to something I longed for: redirection of output back into scripts, when you would be able to use things like:
RunWait, %comspec% dir | %a_script% theoutput
pipe the output back to the script as a variable called theoutput
Weird though that the first version showed your script flawlessly, but on update, the new script and the first script don't work at all :?
I'm on 2kSP4 english, the window texts should be fine...
RunWait, %comspec% dir | %a_script% theoutput
pipe the output back to the script as a variable called theoutput
Weird though that the first version showed your script flawlessly, but on update, the new script and the first script don't work at all :?
I'm on 2kSP4 english, the window texts should be fine...
#4
-
Posted 25 March 2005 - 11:25 PM
Could you be a bit more specific? Which scripts aren't currently working for you? What happens instead of the expected action?Weird though that the first version showed your script flawlessly, but on update, the new script and the first script don't work at all :?
I'm on 2kSP4 english, the window texts should be fine...
#5
-
Posted 25 March 2005 - 11:32 PM
Your first version of the script only returns "CMD" now. Your second version shows the correct info , but if you keep clicking the buttons (calling the program), eventually, the edit gets wrongly updated. The notepad script doesn't write anything...
#6
-
Posted 25 March 2005 - 11:53 PM
Thanks for clarifying .
The 2nd and 3rd methods in the original example script (cmdtst.ahk) don't seem to work on the Win2k system I have tested with. The 1st method seems to work ok though. Thanks for letting me know .
The notepad script tests ok on Win2k here... To test: Start the sample_1.1.ahk script, Start notepad, type "src" (without the quotes) then spacebar (or enter) in Notepad... Does this show the script's source in Notepad for you?
The 2nd and 3rd methods in the original example script (cmdtst.ahk) don't seem to work on the Win2k system I have tested with. The 1st method seems to work ok though. Thanks for letting me know .
The notepad script tests ok on Win2k here... To test: Start the sample_1.1.ahk script, Start notepad, type "src" (without the quotes) then spacebar (or enter) in Notepad... Does this show the script's source in Notepad for you?
#7
-
Posted 26 March 2005 - 12:28 AM
Which script?Now sometimes I got it to work, but I get these errors:
The system cannot find the path specified.
and
Error occurred while processing: and.
:?
If it's the output to notepad script does this change work ok?
::src:: RunWait, %A_ScriptDir%\%RunCMD3%,,Hide ReturnAlso, is CMDret.exe in the script's directory? Which version of AHK are you running?
#9
-
Posted 26 March 2005 - 12:53 AM
It might be an issue with spaces in the path... I have updated the posted version (above). Please let me know if it works ok now. If it doesn't could you please uncomment the
Thanks for the feedback. It is appreciated .
line and let me know the contents of the MsgBox? Also, does typing "pingit" or "winver" in Notepad work ok?; MsgBox, %RunCMD3%
Thanks for the feedback. It is appreciated .
#11
-
Posted 26 March 2005 - 03:57 AM
Interesting... Thanks for the confirmation .found it... :? I don't have 'type' on my system somehow... changed it to 'echo', now all work 8)
#13
-
Posted 26 March 2005 - 05:11 PM
This link at top of thread seems to be broken (today)
http://home.cogeco.c...rupt/cmdret.zip
Has the new dll version of CMDret replaced the above?
I downloaded the dll version o.k. (found by searching on subject "pipes").
http://home.cogeco.c...rupt/cmdret.zip
Has the new dll version of CMDret replaced the above?
I downloaded the dll version o.k. (found by searching on subject "pipes").
#15
-
Posted 15 June 2005 - 10:00 AM