AutoHotkey Community

It is currently May 26th, 2012, 9:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 104 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: December 8th, 2007, 12:41 pm 
I dont really want to use telnet, but a telnetlike application. Can you tell me, how i just get the text of a running application (CMD) into a variable using this function?
I tried the example script, but it seems like interacting with my application, because Im getting a "loopcommand error". Does this function interact in anyway with my app?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2007, 2:02 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
User2001 wrote:
I tried the example script, but it seems like interacting with my application, because Im getting a "loopcommand error". Does this function interact in anyway with my app?

No, it just reads the Stdout pipe. There is nothing to cause Loop error. Please be sure you're using the latest build of AHK, or post your code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2007, 3:17 pm 
I updated AHK to the newest version now and you script doesnt work any longer?!

I think this should work? But it says: "Error Call To Nonexistent Function" Specifically: COM_Init()

Code:
sCmd :=   "ipconfig /all"
;sDir := ""
;sInput := ""

MsgBox,   % StdCreateProcess(sCmd, sDir, sInput)   ; StdCreateProcessCOM(sCmd, sDir, sInput)


StdCreateProcess(sCmd, sDir = "", sInput = "")
{
   If   sInput <>
   CreatePipe(hStdInRd , hStdInWr ),   SetHandleInformation(hStdInRd )
   CreatePipe(hStdOutRd, hStdOutWr),   SetHandleInformation(hStdOutWr)

   VarSetCapacity(pi, 16, 0)
   NumPut(VarSetCapacity(si, 68, 0), si)   ; size of si
   NumPut(0x100   , si, 44)      ; STARTF_USESTDHANDLES
   NumPut(hStdInRd   , si, 56)      ; hStdInput
   NumPut(hStdOutWr, si, 60)      ; hStdOutput
   NumPut(hStdOutWr, si, 64)      ; hStdError
   If Not   DllCall("CreateProcess", "Uint", 0, "Uint", &sCmd, "Uint", 0, "Uint", 0, "int", True, "Uint", 0x08000000, "Uint", 0, "Uint", sDir ? &sDir : 0, "Uint", &si, "Uint", &pi)   ; bInheritHandles and CREATE_NO_WINDOW
      ExitApp
   CloseHandle(NumGet(pi,0)),   CloseHandle(NumGet(pi,4))

   If   sInput <>
   StdInput( sInput , hStdInRd , hStdInWr )
   StdOutput(sOutput, hStdOutRd, hStdOutWr)
   Return   sOutput
}

StdCreateProcessCOM(sCmd, sDir = "", sInput = "")
{
   COM_Init()
   pwsh :=   COM_CreateObject("WScript.Shell")
   sDir ?   COM_Invoke(pwsh, "CurrentDirectory=", sDir) : ""
   pexec:=   COM_Invoke(pwsh, "Exec", sCmd)
   WinWaitActive, ahk_class ConsoleWindowClass,, 1
   WinHide

   If   sInput <>
   pin  :=   COM_Invoke(pexec, "StdIn"), COM_Invoke(pin, "Write", sInput), COM_Invoke(pin, "Close"), COM_Release(pin)
   pout :=   COM_Invoke(pexec, "StdOut")   ; perr := COM_Invoke(pexec, "StdErr")
   Loop
      If   COM_Invoke(pout, "AtEndOfStream")=0
         sOutput   .= COM_Invoke(pout, "ReadLine") . "`r`n"
      Else   Break
   COM_Invoke(pout, "Close"), COM_Release(pout)

   Loop
      If   COM_Invoke(pexec, "Status")=0
         Sleep,   100
      Else   Break
;   COM_Invoke(pexec, "Terminate")
   COM_Release(pexec)
   COM_Release(pwsh)
   COM_Term()
   Return   sOutput
}

StdInput(ByRef sInput, hStdInRd, hStdInWr)
{
   CloseHandle(hStdInRd)
   WriteFile(hStdInWr, &sInput, StrLen(sInput))
   CloseHandle(hStdInWr)
}

StdOutput(ByRef sOutput, hStdOutRd, hStdOutWr)
{
   CloseHandle(hStdOutWr)
   VarSetCapacity(sTemp, 4095)
   Loop
      If   nSize:=ReadFile(hStdOutRd, &sTemp, 4095)
         NumPut(0, sTemp, nSize, "char"), VarSetCapacity(sTemp, -1), sOutput .= sTemp
      Else   Break
   CloseHandle(hStdOutRd)
}

CreatePipe(ByRef hRead, ByRef hWrite)
{
   Return   DllCall("CreatePipe", "UintP", hRead, "UintP", hWrite, "Uint", 0, "Uint", 0)
}

ReadFile(hFile, pBuffer, nSize)
{
   If   DllCall("ReadFile" , "Uint", hFile, "Uint", pBuffer, "Uint", nSize, "UintP", nSize, "Uint", 0)
   Return   nSize
}

WriteFile(hFile, pBuffer, nSize)
{
   If   DllCall("WriteFile", "Uint", hFile, "Uint", pBuffer, "Uint", nSize, "UintP", nSize, "Uint", 0)
   Return   nSize
}

GetHandleInformation(Handle)
{
   If   DllCall("GetHandleInformation", "Uint", Handle, "UintP", nFlags)
   Return   nFlags
}

SetHandleInformation(Handle, nFlags = 1)   ; HANDLE_FLAG_INHERIT = 1
{
   Return   DllCall("SetHandleInformation", "Uint", Handle, "Uint", nFlags, "Uint", nFlags)
}

CloseHandle(Handle)
{
   Return   DllCall("CloseHandle", "Uint", Handle)
}



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2007, 4:13 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Anonymous wrote:
But it says: "Error Call To Nonexistent Function" Specifically: COM_Init()

StdCreateProcessCOM needs COM Standard Library. You may remove this function from the script if you're not going to use it. And, please remove the script StdoutToVar.ahk from your post. You only need to post your own code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2007, 11:52 am 
What is the difference between StdCreateProcess and StdCreateProcessCOM?

I am using an older version of the script and it works well. Are there any advantages of the update other than that I need to write fewer lines of code to use it?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 22nd, 2007, 4:04 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Rizzo wrote:
What is the difference between StdCreateProcess and StdCreateProcessCOM?

I am using an older version of the script and it works well. Are there any advantages of the update other than that I need to write fewer lines of code to use it?

StadCreateProcessCOM uses COM. The update was not bug-fixing, was streamlining. So, you don't have to update it if you don't want to although it's recommended.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2008, 8:48 pm 
Are there any advantages with using the COM or not using the COM?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2008, 5:17 pm 
Offline

Joined: October 27th, 2006, 10:12 am
Posts: 649
Chris wrote:
... I'm sure you have better things to do with your time, but the topmost post could use a bit more introduction (even a single sentence), and possibly a simple usage example. When I examine a post for accessibility and presentation, I ask:

1) What is somone's first impression upon viewing this post?
2) Can someone find out the gist of the post in under 30 seconds? (This helps them decide whether to continue reading the whole thing.)
...
That's maybe also a sign for potential lack of automation/automation market hole for making things easier. :) (Like an .ahk solution which works as a posting template so anyone can fastly fill in the form or just leave them empty or very short limited info it you have less/no time.) See also my previous posting here: http://www.autohotkey.com/forum/viewtop ... 089#179089

It's not only important to have solutions, it's also important to allow/make creative-use of these solutions breaking their initial application spaces.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2008, 5:05 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Streaming ability was added to StdCreateProcess(). If specify the parameter bStream to True it'll create a console window and display line-by-line the result, in addition to returning the result as a whole.
Code:
; Streaming example
sCmd    := "ping www.autohotkey.com"
bStream := True


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2008, 6:00 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
you should make this stdlib compatible.
edit:
thanks again for you contributions to the forum.

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2008, 9:29 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
ahklerner wrote:
you should make this stdlib compatible.
OK, I modified it to be Standard Library compatible, and to use the existing one if allowed when AHK is already attached to a console.

Quote:
thanks again for you contributions to the forum.
You're welcome and thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2008, 6:37 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
ladies and gentlemen ........(crowd gets quiet with anticipation)
Sean!!!!!!!!!! :D
hours later the cheers die down and someone points out soemthing else he did while back and it all starts again
I think the ahk community should have a Sean day
thats it July 12 is National Sean Day

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2008, 1:18 am 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 774
Location: Texas, USA
Hey, I just tried the new version and the Sort example doesn't work anymore. In fact, the AutoHotkey program is stopped before the function returns any value.

Sort example from this post:
http://www.autohotkey.com/forum/viewtop ... 878#162878

Thanks for your help.



Edit: My fault, please disregard. The parameters have changed in the new version.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2008, 3:49 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
jballi wrote:
Edit: My fault, please disregard. The parameters have changed in the new version.

Sorry, I should've mentioned that. I updated the examples accordingly.
BTW, I usually don't change the parameters' order, however, I decided to do it in this case as I thought bStream would be used more frequently than sDir & sInput.

PS. I also updated the function StdoutToVar_CreateProcessCOM() in the script to accommodate the new bStream option.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2008, 3:20 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
removed by poster due to protest from ahk communitysorry to have offended :D

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Last edited by tank on July 13th, 2008, 5:14 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 104 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg, tomoe_uehara and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group