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 

StdoutToVar
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
User2001
Guest





PostPosted: Sat Dec 08, 2007 12:41 pm    Post subject: Reply with quote

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?
Back to top
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Dec 08, 2007 2:02 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Dec 08, 2007 3:17 pm    Post subject: Reply with quote

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)
}

Back to top
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Dec 08, 2007 4:13 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Rizzo
Guest





PostPosted: Sat Dec 22, 2007 11:52 am    Post subject: Reply with quote

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?
Back to top
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Dec 22, 2007 4:04 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Rizzo
Guest





PostPosted: Thu Jan 10, 2008 8:48 pm    Post subject: Reply with quote

Are there any advantages with using the COM or not using the COM?
Back to top
automaticman



Joined: 27 Oct 2006
Posts: 311

PostPosted: Sun Feb 17, 2008 5:17 pm    Post subject: Reply with quote

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. Smile (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/viewtopic.php?p=179089#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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Jul 12, 2008 5:05 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1149
Location: USA

PostPosted: Sat Jul 12, 2008 6:00 am    Post subject: Reply with quote

you should make this stdlib compatible.
edit:
thanks again for you contributions to the forum.
_________________
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Jul 12, 2008 9:29 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 473

PostPosted: Sat Jul 12, 2008 6:37 pm    Post subject: Reply with quote

ladies and gentlemen ........(crowd gets quiet with anticipation)
Sean!!!!!!!!!! Very Happy
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
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
jballi



Joined: 01 Oct 2005
Posts: 320
Location: Texas, USA

PostPosted: Sun Jul 13, 2008 1:18 am    Post subject: Reply with quote

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/viewtopic.php?p=162878#162878

Thanks for your help.



Edit: My fault, please disregard. The parameters have changed in the new version.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sun Jul 13, 2008 3:49 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 473

PostPosted: Sun Jul 13, 2008 3:20 pm    Post subject: Reply with quote

removed by poster due to protest from ahk communitysorry to have offended Very Happy
_________________
Read this
Com
Automate IE7 with Tabs


Last edited by tank on Sun Jul 13, 2008 5:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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