AutoHotkey Community

It is currently May 26th, 2012, 8:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 104 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: July 7th, 2009, 8:53 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Hello n00b.

1. Use my function, it doesn't have ExitApp but returns error message.
2. FIrst one is better.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: thanks..
PostPosted: July 7th, 2009, 9:18 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
Thanks a lot..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2009, 9:50 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2009, 2:50 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 10:58 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 4:02 pm 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 5:54 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thats not the same thing (plus its not 100% reliable)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2009, 12:41 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2009, 8:17 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2009, 4:23 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 12:14 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 1:18 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I guess this is for you:
http://www.autohotkey.com/forum/viewtopic.php?t=36168

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 2:32 pm 
Tried that.. could get the send working, but not the receive !!
Any ideas ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 2:38 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 3:04 pm 
Thanks majkinetor

If you can find the script that may be a big help :)


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: bekihito, Blackholyman, Exabot [Bot] and 12 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