 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Tue Jul 07, 2009 7:53 am Post subject: |
|
|
Hello n00b.
1. Use my function, it doesn't have ExitApp but returns error message.
2. FIrst one is better. _________________
 |
|
| Back to top |
|
 |
shajul
Joined: 15 Sep 2006 Posts: 564
|
Posted: Tue Jul 07, 2009 8:18 am Post subject: thanks.. |
|
|
| Thanks a lot.. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Thu Aug 13, 2009 8:50 pm Post subject: |
|
|
2 Sean
Do you know perhaps, is it feasible to be notified about program requests and respond to them ?
For instance when proggy is asking password.
This would be similar to main use of *nx command expect.
Currently function simply exits when such thing happens. _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Fri Aug 14, 2009 1:50 am Post subject: |
|
|
| majkinetor wrote: | | Do you know perhaps, is it feasible to be notified about program requests and respond to them ? | You meant in the middle of execution, not through sInput, right? I don't think feedback/interaction is possible as it uses anonymous pipes which are one-way flows. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Mon Aug 24, 2009 9:58 am Post subject: |
|
|
| Quote: | | You meant in the middle of execution, not through sInput, right? I don't think feedback/interaction is possible as it uses anonymous pipes which are one-way flows. |
Yes.
If I create console hidden, use AttachConsole to bind to it, I can get its buffer and send keys to it. _________________
 |
|
| Back to top |
|
 |
Crash&Burn
Joined: 02 Aug 2009 Posts: 210
|
Posted: Mon Aug 24, 2009 3:02 pm Post subject: |
|
|
I've read thru this thread, and Lexikos' How to: Run Dynamic Script... Through a Pipe!; as well as some of the links provided in his thread, along with some older threads here.
If all you really need is to run a cmd.exe batch that can return output, wouldn't UnxUtils gclip.exe work? Then AHK can just grab the contents of the clipboard. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Mon Aug 24, 2009 4:54 pm Post subject: |
|
|
Thats not the same thing (plus its not 100% reliable) _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Mon Aug 24, 2009 11:41 pm Post subject: |
|
|
| majkinetor wrote: | | If I create console hidden, use AttachConsole to bind to it, I can get its buffer and send keys to it. | Of course it'll work with a console as it's designed to interact with human inputs. How would you decide if an app is requesting feedback/interaction from an user inside a mere function? Anyway, I can see a way to alter the function which may (or may not) work with your particular app, but it may break with some other apps. Does your app not require input data at startup? Does it not output anymore data, besides the password requesting, at the end? |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Tue Aug 25, 2009 7:17 am Post subject: |
|
|
I don't have any particular console app I want to interact with.... in few ocassions I needed it in different times.
Well, I guess the easiest solution is then to create alternative function (or modify corrupts one) that can do that, instead of modifying this one and breaking some scripts...
| Quote: | | Does your app not require input data at startup? Does it not output anymore data, besides the password requesting, at the end? |
I was calling schtasks to create scheduled task. It asks for password in some cases. It doesn't have stdin but it outputs success or failure message after. _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Aug 25, 2009 3:23 pm Post subject: |
|
|
Here is my attempt. I assumed that the first output from the app is the prompt for password request, and I used Password: for the prompted text here, so replace it with the exact words your app actually prompts for the password. There still remain one or two unclear points to me which will be next target if the code doesn't work.
| Code: | StdoutToVar_CreateProcessEx(sCmd, bStream = "", sDir = "")
{
DllCall("CreatePipe", "UintP", hStdInRd , "UintP", hStdInWr , "Uint", 0, "Uint", 0)
DllCall("CreatePipe", "UintP", hStdOutRd, "UintP", hStdOutWr, "Uint", 0, "Uint", 0)
DllCall("SetHandleInformation", "Uint", hStdInRd , "Uint", 1, "Uint", 1)
DllCall("SetHandleInformation", "Uint", hStdOutWr, "Uint", 1, "Uint", 1)
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
DllCall("CloseHandle", "Uint", NumGet(pi,0))
DllCall("CloseHandle", "Uint", NumGet(pi,4))
DllCall("CloseHandle", "Uint", hStdOutWr)
DllCall("CloseHandle", "Uint", hStdInRd)
bStream+0 ? (bAlloc:=DllCall("AllocConsole"),hCon:=DllCall("CreateFile","str","CON","Uint",0x40000000,"Uint",bAlloc ? 0 : 3,"Uint",0,"Uint",3,"Uint",0,"Uint",0)) : ""
nTrim:=1
Loop
{
If DllCall("ReadFile", "Uint", hStdOutRd, "UcharP", nChr, "Uint", 1, "UintP", nSize:=0, "Uint", 0)&&nSize
{
sOutput.=Chr(nChr)
If bStream
Loop
If RegExMatch(sOutput, "[^\n]*\n", sTrim, nTrim)
bStream+0 ? DllCall("WriteFile", "Uint", hCon, "Uint", &sTrim, "Uint", StrLen(sTrim), "UintP", 0, "Uint", 0) : %bStream%(sTrim), nTrim+=StrLen(sTrim)
Else Break
}
Else Break
If (sOutput="Password:")
{
sOutput:=""
InputBox, sInput
DllCall("WriteFile", "Uint", hStdInWr, "Uint", &sInput, "Uint", StrLen(sInput), "UintP", nSize, "Uint", 0)
DllCall("CloseHandle", "Uint", hStdInWr)
}
}
DllCall("CloseHandle", "Uint", hStdOutRd)
bStream+0 ? (DllCall("Sleep","Uint",1000),hCon+1 ? DllCall("CloseHandle","Uint",hCon) : "",bAlloc ? DllCall("FreeConsole") : "") : ""
Return sOutput
}
|
|
|
| Back to top |
|
 |
Tom Guest
|
Posted: Thu Dec 10, 2009 11:14 am Post subject: |
|
|
Hi
When I log into the telnet session is spews out a constant stream of data.
Normally this just wizz's past in the open telnet window.
I'm trying to find a way to monitor the output and then run a specific action if a keyword is outputted.
Can anyone offer any advice ??
Thanks |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
|
| Back to top |
|
 |
Tom Guest
|
Posted: Thu Dec 10, 2009 1:32 pm Post subject: |
|
|
Tried that.. could get the send working, but not the receive !!
Any ideas ? |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Thu Dec 10, 2009 1:38 pm Post subject: |
|
|
Well, actually I managed to do what you want, however, I currently don't remember how I did it. Ill take a look if I can find if that script still exists. I managed to start the program which at some point asks for password and send it out to it.
I think it was using AttachConsole from somewhere on this forum, and simple Send command.
U shoud perhaps try in this direction:
| Quote: | | Stream If set to TRUE it will create a console window and display output line-by-line, in addition to returning the result as a whole. If string, name of the function to be called as output updates (stream handler). The function accepts one argument. |
You need to modify func sO that u both have line-by-line streaming while console window is shown (what you get when you pass TRUE). Then u can get lines and send content to window by using Send or ConsoleSend. _________________
 |
|
| Back to top |
|
 |
Tom Guest
|
Posted: Thu Dec 10, 2009 2:04 pm Post subject: |
|
|
Thanks majkinetor
If you can find the script that may be a big help  |
|
| 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
|