AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CMDret - return output from console progs [DLL version]
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources
View previous topic :: View next topic  
Author Message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Thu Nov 27, 2008 1:23 am    Post subject: Reply with quote

Serenity wrote:
It doesn't. I get a << Process Terminated by Esc Key >> message and then it freezes/crashes.
Thanks for the feedback. I am able to reproduce this error with version 3.2.1 and above on Windows 2000 SP4 but I was not able to reproduce the error with version 3.1.2 (also available for download in the first post).
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Mon Dec 08, 2008 12:19 pm    Post subject: Reply with quote

CMDret 4c (BETA) - Download (cmdret.dll + a couple of test scripts)

- updated the RunWCB() function for Win2k compatibility (hopefully)

I would appreciate feedback from anyone that has a chance to test this version. Only the RunWCB() function has been updated in this Beta version. If this seems to fix the issue when running in Windows 2000 then I'll update the other functions in the next release Smile .
Back to top
View user's profile Send private message Visit poster's website
Serenity



Joined: 08 Nov 2004
Posts: 1272

PostPosted: Tue Dec 09, 2008 12:06 am    Post subject: Reply with quote

Thanks corrupt. Smile I tried both scripts and neither crashed.
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
oldHacker



Joined: 06 Feb 2008
Posts: 14
Location: the land of enchantment

PostPosted: Tue Dec 09, 2008 1:34 am    Post subject: Reply with quote

corrupt wrote:
...If this seems to fix the issue when running in Windows 2000...

thanks i'll give it a go ~ let you know Cool
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Sun Dec 14, 2008 11:03 pm    Post subject: Reply with quote

CMDret 4d Beta - Download (cmdret.dll, cmdstub.exe, several test scripts)
- updated all functions for Windows 2000 compatibility (hopefully)
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Mon Dec 22, 2008 11:00 am    Post subject: Reply with quote

Serenity wrote:
Thanks corrupt. Smile I tried both scripts and neither crashed.
Thanks for the feedback Smile .
Back to top
View user's profile Send private message Visit poster's website
RedShadow_
Guest





PostPosted: Fri Jul 03, 2009 8:16 am    Post subject: Reply with quote

Hey you guys,

The issue with the script not responding is related to threads.
When you make the dllCall the script waits for the call to end.

I made a script to launch a Tomcat server, and for that, I wanted to be able to grab the console output for debugging purposes.
The trouble I had was that the Tomcat server is not suposed to end.
Thus, is was freezing the script.

The solution is to make the dllCall into a separate thread.
See:

Code:

;// Consts
WINDOW_TITLE    = Tomcat Console

;// GUI
Menu, Tray, NoStandard
Menu, Tray, Add, Exit, GuiClose
Gui, +ToolWindow
Gui, Add, Edit, x6 y10 w460 h360 +HScroll HWNDoutputh
Gui, Show, center h377 w477, %WINDOW_TITLE%
WinWait, %WINDOW_TITLE%

;// Create CMD
CMD := COMSPEC . " /C dir c:\*.* /b /s"

;// Make thread
CBA_PIPE := RegisterCallback( "pipeThread" )  ;// pipeThread is the function to run in a separate thread
threadID := DllCall( "CreateThread", UInt,0, UInt,0, UInt,CBA_PIPE, UInt,0, UInt,0, UInt,0 )

;// Loop
Return

;// Quit
GuiClose:
        ;// Kill the stuff
        Process, Close, "cmd.exe", 10   ;// not sure this works but whatever

   ;// Kill thread
   DllCall( "TerminateThread", UInt, threadID, UInt, 0 )
   DllCall( "CloseHandle", UInt, threadID )
   ExitApp, 0


;/**
; * Thread that writes to text area.
; */
pipeThread() {
   global cmd, outputh
   rc := DllCall("cmdret.dll\RunInControl", "str", CMD, "Uint", outputh) ;// outputh is the handler to the text area
}


I didnt test that code, its just to illustrate the thread stuff with CMDRet.
I used CMDret 4b BTW.

Hope that was usefull.

Cya Cool
Back to top
DavidA



Joined: 13 May 2009
Posts: 10

PostPosted: Tue Jul 07, 2009 12:30 am    Post subject: Reply with quote

I'm trying to use this in conjunction with a third party perl script. It's a perl script that downloads a FLV file by calling command line programs (e.g. rtmpdump.exe)

The problem I'm having is that CMDRet doesn't seem to be handling the output in the same way that a console window would. Specifically, there's a part of the perl script that shows a percentage complete. In a regular Windows DOS box it looks like a percentage that increases 'on the spot', i.e. the cursor stays at the same position and the percentage increases.

If I use the function method (CMDret_Stream) then I see no percentage progress at all until it's completely done, and then for some reason it doesn't show the newline characters properly. e.g.

[]0.051 KB[]0.108 KB[]0.605 KB (0.0%)[]0.679 KB (0.0%)[]0.752 KB[](0.0%)[]17.865 KB (0.0%)[]17.884 KB (0.0%)[]18.179 KB (0.0%)

...for lines and lines all the way up to 100, where [] is shown as a box which is in fact a newline character. (I couldn't paste the exact code here as the box gets translated into new lines).

If I use the DLL test script (testx3.ahk or cmdret4b_1.ahk) then I see the progress as it happens, but again, the newline character is instead shown as a square. Since I'm seeing the progress as it happens, I ought to be able to parse it and display it properly, but I don't know how to do that since it's going directly to the Edit Box.

Here's what it looks like in the testx3.ahk



Anyone know how I can a) avoid the newline characters showing up as boxes? b) parse the output from the dll before it gets to the Edit Box?

Thanks in advance.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Sat Jul 11, 2009 6:53 pm    Post subject: Reply with quote

DavidA wrote:
Anyone know how I can a) avoid the newline characters showing up as boxes? b) parse the output from the dll before it gets to the Edit Box?

Thanks in advance.
You might want to have a look at the examples for the RunWCB() function in the dll. A StripNull() function has been added to the examples in attempt to compensate for Null, non-printable characters in the output that AHK does not currently handle the same way.
Back to top
View user's profile Send private message Visit poster's website
DavidA



Joined: 13 May 2009
Posts: 10

PostPosted: Sun Jul 12, 2009 10:54 pm    Post subject: Reply with quote

Thanks Corrupt. The memory handling in cmdret4b_1 is a little beyond me, but I think I've made some progress.

I've changed your example so that it parses the data using my own parser:

Code:
VarSetCapacity(TOut, nchar + 1, 0)
DllCall(df_lstrcat, "str", TOut, "UInt", cmdout)
VarSetCapacity(TOut, -1)
StripNull(TOut, nchar) ; remove NULL characters from output
ParseData(TOut, nchar)
;DllCall(df_SendMessage, "UInt", Ed1, "UInt", 0xC2, "UInt", 0, "UInt", &TOut)


Notice the new line, ParseData and the DLLCall on the following line remarked out.

And then my ParseData routine is as follows:

Code:
ParseData(strData, intCharacters)
{   
  global Ed1
  Loop, Parse, strData, `r`n
  {
    if %A_LoopField%
    {
      strThisLine = %A_LoopField%
      SendMessage 0xB1, -2, -1, , ahk_id %Ed1%
      Control, EditPaste, %strThisLine%`r`n, , ahk_id %Ed1%
    }
  }
}


It works, but I'm not sure how dangerous it is to handle the data in that way. It's the only way I understand right now. Would that be safe?
Back to top
View user's profile Send private message
skyd1v3r



Joined: 18 Jun 2009
Posts: 73

PostPosted: Mon Jul 13, 2009 9:49 pm    Post subject: Reply with quote

Just a short wort of thank.
I am recently learning C#, and thanks to your file I can hopefully use my C#-work to speed up some of my AHK-Scripts.

Localisation issue
On the german version of WinXP3, all the ä, ö, and ü (no idea if displayed in your browser) get hopelessly screwed up.

Is there any Idea for a solution?


A question to speed:
As I will need to call this DLL about 50.000 times in a loop, I´d like to understand that part of the documentations:
Code:

; In the following example, if the DLL isn't yet loaded, use LoadLibrary in place of GetModuleHandle.
MulDivProc := DllCall("GetProcAddress", uint, DllCall("GetModuleHandle", str, "kernel32"), str, "MulDiv")
Loop 500
    DllCall(MulDivProc, int, 3, int, 4, int, 3)


I do not see where to enter the "cmdret.dll".

Please could anyone give the code?
I am going to insert it right after
Code:

hModule := DllCall("LoadLibrary", "str", "cmdret.dll") 


Thanks in advance!
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Sep 07, 2009 8:03 am    Post subject: Reply with quote

why this doesnt work

Code:
; CMDret DLL version 3.1 (or greater) required

Run, Notepad,,, notepid
WinWait, ahk_pid %notepid%
WinWaitActive, ahk_pid %notepid%

CMD := "dir"
ControlGet, OutputWindow, Hwnd,, Edit1, ahk_pid %notepid%
if OutputWindow <> 0
  StrOut := DllCall("cmdret.dll\RunInControl", "str", CMD, "Uint", OutputWindow, "str", "Edit", "int", "1")
Back to top
cruzer



Joined: 11 Feb 2009
Posts: 11

PostPosted: Sun Oct 25, 2009 3:32 am    Post subject: Reply with quote

hi,
how do I make the CMD work when the program requires parameters?

this works:
Code:
CMD := "C:\Program Files\Wireshark\tshark.exe"


but as soon as I add parameters it won't work. I don't get any output so I guess the program won't be executed/found:

Quote:
CMD := "C:\Program Files\Wireshark\tshark.exe port 6112 -T fields -e data"


how do I get it work with parameters??

of course it has to be:
Quote:
"C:\Program Files\Wireshark\tshark.exe" port 6112 -T fields -e data
, in quotes, but since the CMD := "" already needs those two "" it doenst work!! and I can't find a syntax descriptiin in the autohotkey documentation.... in most languages \" would work but in ahk it doesnt!! Twisted Evil

here is the complety code:
Code:

;// Consts
WINDOW_TITLE    = Tomcat Console

;// GUI
Menu, Tray, NoStandard
Menu, Tray, Add, Exit, GuiClose
Gui, Add, Edit, x6 y10 w790 h790 +HScroll HWNDoutputh
Gui, Show, center h800 w800, %WINDOW_TITLE%
WinWait, %WINDOW_TITLE%

;// Create CMD
CMD := "C:\Program Files\Wireshark\tshark.exe port 6112 -T fields -e data"

;// Make thread
CBA_PIPE := RegisterCallback( "pipeThread" )  ;// pipeThread is the function to run in a separate thread
threadID := DllCall( "CreateThread", UInt,0, UInt,0, UInt,CBA_PIPE, UInt,0, UInt,0, UInt,0 )

;// Loop
Return

;// Quit
GuiClose:
        ;// Kill the stuff
        Process, Close, "cmd.exe",   ;// not sure this works but whatever

   ;// Kill thread
   DllCall( "TerminateThread", UInt, threadID, UInt, 0 )
   DllCall( "CloseHandle", UInt, threadID )
   ExitApp, 0


;/**
; * Thread that writes to text area.
; */
pipeThread() {
   global cmd, outputh
   rc := DllCall("cmdret.dll\RunInControl", "str", CMD, "Uint", outputh) ;// outputh is the handler to the text area
}

Back to top
View user's profile Send private message
flak



Joined: 02 Oct 2009
Posts: 69

PostPosted: Sun Oct 25, 2009 7:56 am    Post subject: Reply with quote

Code:
CMD := """C:\Program Files\Wireshark\tshark.exe"" port 6112 -T fields -e data"
Back to top
View user's profile Send private message
cruzer



Joined: 11 Feb 2009
Posts: 11

PostPosted: Sun Oct 25, 2009 6:01 pm    Post subject: Reply with quote

flak wrote:
Code:
CMD := """C:\Program Files\Wireshark\tshark.exe"" port 6112 -T fields -e data"

works, thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Page 9 of 10

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group