Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CMDret - return output from console progs [DLL version]


  • Please log in to reply
172 replies to this topic
zzzooo10
  • Members
  • 237 posts
  • Last active: May 18 2014 03:14 AM
  • Joined: 19 Dec 2010

The tool is really great! But do not support ahk unicode version rightnow, what a pity! :?

I'm not currently using AhkL but will look into it. Thanks

I would appreciate it if you got this to work worth AutoHotkey_L Unicode 32 bit :D

  • Guests
  • Last active:
  • Joined: --

The tool is really great! But do not support ahk unicode version rightnow, what a pity! :?

I'm not currently using AhkL but will look into it. Thanks

I would appreciate it if you got this to work worth AutoHotkey_L Unicode 32 bit :D


use

libiconv: character set conversion library


or win api
/*
CP_ACP   = 0
CP_OEMCP = 1
CP_MACCP = 2
CP_UTF7  = 65000
CP_UTF8  = 65001
*/

Ansi2Oem(sString)
{
   Ansi2Unicode(sString, wString, 0)
   Unicode2Ansi(wString, zString, 1)
   Return zString
}

Oem2Ansi(zString)
{
   Ansi2Unicode(zString, wString, 1)
   Unicode2Ansi(wString, sString, 0)
   Return sString
}

Ansi2UTF8(sString)
{
   Ansi2Unicode(sString, wString, 0)
   Unicode2Ansi(wString, zString, 65001)
   Return zString
}

UTF82Ansi(zString)
{
   Ansi2Unicode(zString, wString, 65001)
   Unicode2Ansi(wString, sString, 0)
   Return sString
}

Ansi2Unicode(ByRef sString, ByRef wString, CP = 0)
{
     nSize := DllCall("MultiByteToWideChar"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &sString
      , "int",  -1
      , "Uint", 0
      , "int",  0)

   VarSetCapacity(wString, nSize * 2)

   DllCall("MultiByteToWideChar"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &sString
      , "int",  -1
      , "Uint", &wString
      , "int",  nSize)
}

Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
{
     nSize := DllCall("WideCharToMultiByte"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &wString
      , "int",  -1
      , "Uint", 0
      , "int",  0
      , "Uint", 0
      , "Uint", 0)

   VarSetCapacity(sString, nSize)

   DllCall("WideCharToMultiByte"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &wString
      , "int",  -1
      , "str",  sString
      , "int",  nSize
      , "Uint", 0
      , "Uint", 0)
}


fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007
Instead of doing what the Guest said, you can use built-in features such as the ASTR DllCall type, StrGet(), etc.

  • Guests
  • Last active:
  • Joined: --
well
the
CMDret - v3.2.1 (DLL version)
were killed by antivirus
and CMDret 4d Beta were ok

and
CMD := "ipconfig /all"
the msgbox were empty on a non-english OS
and StdoutToVar were ok

amnesiac
  • Members
  • 124 posts
  • Last active: May 01 2014 03:04 AM
  • Joined: 07 Nov 2010
Thanks for your work!

I think using WshShell Object maybe a better way. For details, please see:
[AHK&AHK_l]Using COM to interact with command-line progs

Jennifer_P
  • Members
  • 42 posts
  • Last active: Nov 28 2011 04:56 PM
  • Joined: 06 Jul 2011
Rats! This program looked like just what I needed, but without the ability to send user input to the console window before outputting the window's contents I can't use it.

So I'll just add a +1 for that feature, if you're still working on this program. :)

Nazzal
  • Members
  • 265 posts
  • Last active: Jan 19 2014 04:31 PM
  • Joined: 19 Nov 2010
I tried using the example in the first page to stream something out but didn't work, I'm I doing something wrong?

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
CMD = "D:\df.exe" c: /large *.* 100

OutputWindow := WinExist("CMDret - DLL version - Streaming Test App")
StrOut := DllCall("cmdret.dll\RunInControl", "str", CMD, "Uint", OutputWindow, "str", "Edit", "int", "1")
Return

GuiClose:
ExitApp
df.exe = commandline version of defraggler

bmoore45
  • Members
  • 273 posts
  • Last active: Mar 14 2012 01:00 PM
  • Joined: 10 Jul 2011
hi corrupt,

will this work with psql.exe?

corrupt
  • Members
  • 2558 posts
  • Last active: May 17 2013 01:30 AM
  • Joined: 29 Dec 2004
Sample script for ANSI or UNICODE 32bit _L versions using the current version of cmdret.dll
ret1 := CMDret(COMSPEC " /C set") 
MsgBox, % ret1 

CMDret(CMD) 
{ 
  VarSetCapacity(StrOut, 20000)
  RetVal := DllCall("cmdret.dll\RunReturn", A_IsUnicode ? "AStr" : "Str", CMD, "Str", StrOut)
  Return, A_IsUnicode ? StrGet(&StrOut, "cp0") : StrOut
} 


corrupt
  • Members
  • 2558 posts
  • Last active: May 17 2013 01:30 AM
  • Joined: 29 Dec 2004
Streaming example (ANSI or UNICODE 32bit _L)
; ---------------------------------------------------------------------------
; CMDret 4b - Beta test
; March 15, 2012 - corrupt
; 
; cmdret version 4b or above required 
; _L ANSI or UNICODE 32bit compatibile
; ---------------------------------------------------------------------------

Gui, Add, Edit, x6 y50 w420 h590 +WantReturn HwndEd1, 
Gui, Add, Button, x6 y10 w100 h30 gRunCMD, Run Command
Gui, Add, Edit, x116 y10 w200 h30 -Multi vcmd1, ping 127.0.0.1 -n 10
Gui, Add, Button, x327 y10 w100 h30 gClr, Clear
Gui, Add, StatusBar, , Ready
Gui, Show, h666 w432, CMDret 4b - Beta
Return

GuiClose:
ExitApp



RunCMD:
  Gui, Submit, NoHide
  If not EnumAddress
    EnumAddress := RegisterCallback("cmdoutProc", "", 4)
  SB_SetText("Executing... Hold <Esc> to terminate")
  ; ---------------------------------------------------------------------------
  ; RunWCB -> CMD=command to execute, EnumAddress=Address from RegisterCallback
  ; ---------------------------------------------------------------------------
  RetVal := DllCall("cmdret.dll\RunWCB", A_IsUnicode ? "AStr" : "Str", cmd1, "UInt", EnumAddress)
  If !(RetVal)
    SB_SetText("Failed to Execute...")
  Else
    SB_SetText("Ready")
Return



cmdoutProc(cmdpid, nchar, cmdout, FutureUse)
{
  global Ed1 ; Edit control HWND
; ---------------------------------------------------------------------------
  Static df_lstrcat
  Static df_SendMessage

  If !(df_lstrcat)
    df_lstrcat := DllCall("GetProcAddress", UInt, DllCall("GetModuleHandle", Str, "kernel32"), A_IsUnicode ? "AStr" : "Str", "lstrcat")
  If !(df_SendMessage)
    df_SendMessage := DllCall("GetProcAddress", UInt, DllCall("GetModuleHandle", Str, "user32"), A_IsUnicode ? "AStr" : "Str", "SendMessageA")

; ---------------------------------------------------------------------------
; Values returned: 
; cmdpid = ProcessId
; ** = WM_USER + 1
; nchar = number of characters returned in the buffer
; cmdout = pointer to the buffer
; FutureUse = FutureUse
; ---------------------------------------------------------------------------
    VarSetCapacity(TOut, nchar + 1, 0)
    DllCall(df_lstrcat, "str", TOut, "UInt", cmdout)
    VarSetCapacity(TOut, -1) 
    StripNull(TOut, nchar) ; remove NULL characters from output
    DllCall(df_SendMessage, "UInt", Ed1, "UInt", 0xC2, "UInt", 0, "UInt", &TOut)
    If (GetKeyState("Esc" , "P")) {
	  Process, Close, %cmdpid%
      DllCall(df_SendMessage, "UInt", Ed1, "UInt", 0xC2, "UInt", 0, "Str", "`r`n`r`n<<  Process Terminated by Esc Key  >>")
	}
    Sleep, 0  ; short sleep to allow minimizing/restoring window   
    Return TRUE
}



StripNull(Var1, DataSize)
{
  Local Static df_RtlZeroMemory
  If !(df_RtlZeroMemory)
    df_RtlZeroMemory := DllCall("GetProcAddress", uint, DllCall("GetModuleHandle", str, "kernel32"), A_IsUnicode ? "AStr" : "Str", "RtlZeroMemory")
  Var1 := A_IsUnicode ? StrGet(&Var1, "cp0") : Var1
  IF (StrLen(Var1) < (DataSize - 1)) { 
    VarSetCapacity(CMcpy, DataSize, 32) 
    DataSize2 = %DataSize% 
    Loop { 
      DllCall(df_RtlZeroMemory, "UInt", &CMcpy, Int, DataSize) 
      NULLptr := StrLen(Var1) 
      cpsize := DataSize - NULLptr 
      DllCall(df_RtlZeroMemory, "UInt", &CMcpy, "UInt", (&Var1 + NULLptr + 2), "Int", (cpsize - 1)) 
      DllCall(df_RtlZeroMemory, "UInt", (&Var1 + NULLptr), Int, cpsize) 
      DllCall(df_RtlZeroMemory, "UInt", (&Var1 + NULLptr), "UInt", &CMcpy, "Int", cpsize) 
      DataSize2 -- 
      IF (StrLen(Var1) > DataSize2) 
        break 
    } 
  } 
  VarSetCapacity(Var1, -1)
Return Var1
} 

Clr:
GuiControl,, Edit1, 
SB_SetText("Ready")
Return 


tain
  • Members
  • 62 posts
  • Last active: May 21 2014 10:02 PM
  • Joined: 16 Feb 2010

CMD := "ipconfig /all"
the msgbox were empty on a non-english OS
and StdoutToVar were ok


I have this issue as well. Having trouble diagnosing it. On Win7 64bit with latest CMDRet and non-L AHK, the ability to pass output to a var and display in a MsgBox is inconsistent for me. Even the sample code from corrupt is failing for me now.

corrupt
  • Members
  • 2558 posts
  • Last active: May 17 2013 01:30 AM
  • Joined: 29 Dec 2004


CMD := "ipconfig /all"
the msgbox were empty on a non-english OS
and StdoutToVar were ok


I have this issue as well. Having trouble diagnosing it. On Win7 64bit with latest CMDRet and non-L AHK, the ability to pass output to a var and display in a MsgBox is inconsistent for me. Even the sample code from corrupt is failing for me now.

I'm currently using Win7 64 bit. Would you be able to post the code that you are currently trying to use (or PM if you prefer)? The last code I posted was for use with AHK_L

tain
  • Members
  • 62 posts
  • Last active: May 21 2014 10:02 PM
  • Joined: 16 Feb 2010
I was referring to sample code from the first post.

corrupt
  • Members
  • 2558 posts
  • Last active: May 17 2013 01:30 AM
  • Joined: 29 Dec 2004

I was referring to sample code from the first post.

There seems to be an issue with using params with the RunReturn function. For example, "ipconfig" seems to work ok here but not "ipconfig /all". It has been a while since I put it together but I'll dig out the source for the dll file and have a look. As an alternative, the following seems to work on this machine. Please let me know if this works for you:
CMD := "ipconfig /all"
RunWaitEx(CMD,"","", stdout, stderr)
MsgBox % stdout

RunWaitEx(CMD, CMDdir, CMDin, ByRef CMDout, ByRef CMDerr, Capx=100000) 
{ 
  VarSetCapacity(CMDOut, Capx) 
  VarSetCapacity(CMDerr, Capx) 
  Return, % DllCall("cmdret.dll\RunWEx", "str", CMD, "str", CMDdir, "str", CMDin, "str", CMDout, "str", CMDerr) 
} 


blode
  • Members
  • 25 posts
  • Last active: Apr 27 2013 04:49 PM
  • Joined: 11 Jul 2012
does anyone have a mirror for version 4?