 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
User2001 Guest
|
Posted: Sat Dec 08, 2007 12:41 pm Post subject: |
|
|
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
|
Posted: Sat Dec 08, 2007 2:02 pm Post subject: |
|
|
| 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 |
|
 |
Guest
|
Posted: Sat Dec 08, 2007 3:17 pm Post subject: |
|
|
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
|
Posted: Sat Dec 08, 2007 4:13 pm Post subject: |
|
|
| 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 |
|
 |
Rizzo Guest
|
Posted: Sat Dec 22, 2007 11:52 am Post subject: |
|
|
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
|
Posted: Sat Dec 22, 2007 4:04 pm Post subject: |
|
|
| 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 |
|
 |
Rizzo Guest
|
Posted: Thu Jan 10, 2008 8:48 pm Post subject: |
|
|
| Are there any advantages with using the COM or not using the COM? |
|
| Back to top |
|
 |
automaticman
Joined: 27 Oct 2006 Posts: 311
|
Posted: Sun Feb 17, 2008 5:17 pm Post subject: |
|
|
| 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/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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Sat Jul 12, 2008 5:05 am Post subject: |
|
|
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.
|
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1149 Location: USA
|
Posted: Sat Jul 12, 2008 6:00 am Post subject: |
|
|
you should make this stdlib compatible.
edit:
thanks again for you contributions to the forum. _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Sat Jul 12, 2008 9:29 am Post subject: |
|
|
| 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 |
|
 |
tank
Joined: 21 Dec 2007 Posts: 473
|
Posted: Sat Jul 12, 2008 6:37 pm Post subject: |
|
|
ladies and gentlemen ........(crowd gets quiet with anticipation)
Sean!!!!!!!!!!
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 |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 320 Location: Texas, USA
|
Posted: Sun Jul 13, 2008 1:18 am Post subject: |
|
|
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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Sun Jul 13, 2008 3:49 am Post subject: |
|
|
| 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 |
|
 |
tank
Joined: 21 Dec 2007 Posts: 473
|
Posted: Sun Jul 13, 2008 3:20 pm Post subject: |
|
|
removed by poster due to protest from ahk communitysorry to have offended  _________________ 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|