connecting to existing named pipe read freezes script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
usermane2022
Posts: 3
Joined: 18 Jul 2022, 20:28

connecting to existing named pipe read freezes script

Post by usermane2022 » 18 Jul 2022, 21:14

Hi,

I'm trying to have AHK read (doesn't need to write) from an existing named pipe created by a small nodejs test server but the script freezes until it receives data..is there a way it can act normal (not freeze, accept hotkeys, etc) and act more on events like a websocket, or chatserver, etc?

The code below is slightly modified Read.AHK from https://www.autohotkey.com/board/topic/103403-ipc-using-named-pipes/

I just put it in a loop and added a GUI to read line by line but it also gives the error The following variable name contains an illegal character: "welcome"

I also found viewtopic.php?t=9858 but I think that's more or less the opposite of what I need.

Code: Select all

ptr := A_PtrSize ? "Ptr" : "UInt"
char_size := A_IsUnicode ? 2 : 1

pipe_name := "\\.\pipe\testpipe"

Gui,Add,Edit,x0 y0 W640 h480 vedittxt,
GuiControl,,Edit1
Gui,Show,Center, w640 h480

While !DllCall("WaitNamedPipe", "Str", pipe_name, "UInt", 0xffffffff)
    Sleep, 500
Loop {

Loop, read, %pipe_name%

ToolTip, %A_LoopReadLine%
;txt :=  %A_LoopReadLine% 
;txt := RegExReplace(%A_LoopReadLine%, [^a-zA-Z], Replacement="")
guicontrol,, edittxt, %txt% 
}
[Mod edit: [code][/code] tags added.]


lexikos
Posts: 9589
Joined: 30 Sep 2013, 04:07
Contact:

Re: connecting to existing named pipe read freezes script

Post by lexikos » 11 Aug 2022, 22:51

Using PeekNamedPipe to determine whether data is already available is probably easier than using overlapped I/O.

Post Reply

Return to “Ask for Help (v1)”