 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Tue Jan 25, 2005 9:20 am Post subject: CMDret - Capture Output from Console [CMD] |
|
|
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.
Last edited by corrupt on Sun May 22, 2005 9:46 pm; edited 8 times in total |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Tue Mar 22, 2005 9:46 pm Post subject: |
|
|
Another sample script that uses CMDret...
(watch for wordwrap...)
| Code: | ; ---------------------------------------------------------------------------------------------
;
; 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
; -----------------------------------------------------------
|
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Fri Mar 25, 2005 10:44 pm Post subject: |
|
|
Redirect to Notepad example using CMDret version 1.1:
| Code: | #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
|
Last edited by corrupt on Sat Mar 26, 2005 4:48 am; edited 1 time in total |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Sat Mar 26, 2005 12:25 am Post subject: |
|
|
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... _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Sat Mar 26, 2005 12:32 am Post subject: |
|
|
| daonlyfreez wrote: | 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... |
Could you be a bit more specific? Which scripts aren't currently working for you? What happens instead of the expected action? |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Sat Mar 26, 2005 12:53 am Post subject: |
|
|
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... _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Sat Mar 26, 2005 1:28 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Sat Mar 26, 2005 1:50 am Post subject: |
|
|
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.
 _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Sat Mar 26, 2005 1:53 am Post subject: |
|
|
| daonlyfreez wrote: | 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.
 | Which script?
If it's the output to notepad script does this change work ok?
| Code: | ::src::
RunWait, %A_ScriptDir%\%RunCMD3%,,Hide
Return |
Also, is CMDret.exe in the script's directory? Which version of AHK are you running? |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Sat Mar 26, 2005 2:38 am Post subject: |
|
|
The change doesn't make any difference.
Version 1.0.30.04 of AutoHotkey
Have to go to sleep now, gotta work over the weekend Hope this is just something on my system...
Good luck! _________________ (sorry, homesite offline atm)
Last edited by daonlyfreez on Sat Mar 26, 2005 3:24 pm; edited 1 time in total |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Sat Mar 26, 2005 4:57 am Post subject: |
|
|
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 | Quote: | | ; MsgBox, %RunCMD3% | line and let me know the contents of the MsgBox? Also, does typing "pingit" or "winver" in Notepad work ok?
Thanks for the feedback. It is appreciated . |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Sat Mar 26, 2005 3:26 pm Post subject: |
|
|
found it... I don't have 'type' on my system somehow... changed it to 'echo', now all work  _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Sat Mar 26, 2005 6:11 pm Post subject: |
|
|
| daonlyfreez wrote: | found it... I don't have 'type' on my system somehow... changed it to 'echo', now all work  | Interesting... Thanks for the confirmation . |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2399
|
Posted: Sun May 22, 2005 7:48 pm Post subject: |
|
|
| DLL Version now available here |
|
| Back to top |
|
 |
dragonfly
Joined: 09 Jun 2005 Posts: 18
|
Posted: Wed Jun 15, 2005 11:00 am Post subject: |
|
|
This link at top of thread seems to be broken (today)
http://home.cogeco.ca/~icorrupt/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"). |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|