Trying to open an existing named pipe in Windows 10 - errno 22, Invalid Argument, but why?

Viewed 418

I'm writing/experimenting with a python script that needs to connect to an existing named pipe in Windows 10. I'm using Python 3.8.

The Named Pipe

Specifically, I'm trying to connect to a pipe named SendPipe1 and write 14 ascii-encoded characters to it.

The pipe was created by some other software (driver?) for a device connected to my PC. I am connecting to it to try to interact with the device in the same way the manufacturer-provided software does. The manufacturer-provided software connects to this same pipe and sends a coded message to it, which commands the device to do something. This is what I'd like to do.

I know the pipe already exists from running the PipeList utility:

PipeList v1.02 - Lists open named pipes
Copyright (C) 2005-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Pipe Name                                    Instances       Max Instances
---------                                    ---------       -------------
[...]
chrome.blah.foo                                   1                1
SendPipe1                                         1               -1
ReceivePipe1                                      1               -1
chrome.blah.bar                                   1                1
[...]

The Code

Here is what I have right now:

ACTIVE_DISP_ID = 1
msg = f'6;16;100;{ACTIVE_DISP_ID};1\r\n'
pipe_path = f'\\\\.\\PIPE\\SendPipe{ACTIVE_DISP_ID}'

try:
    f = open(pipe_path, 'wb+', buffering=0)
    f.write(msg.encode(encoding='ascii'))
except OSError as e:
    raise

which gives me

The Error(s)

Traceback (most recent call last):
  File "C:/Users/Spooqi/PycharmProjects/Spooqi/radiant/pipe-test.py", line 7, in <module>
    f = open(pipe_path, 'wb+', buffering=0)
OSError: [Errno 22] Invalid argument: '\\\\.\\PIPE\\SendPipe1'

I am fairly certain the path '\\\\.\\PIPE\\SendPipe1' is correct, because if I change it to something like '\\\\.\\PIPE\\FooPipeBar', I get a different Exception:

FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\PIPE\\FooPipeBar'

and if I write to a regular file that doesn't (yet) exist with relative path foobar it will just produce a text file with that message normally.

The Question(s)

In this context, what does errno 22 mean? Why is this argument invalid? Why can't I connect to this pipe and write to it?

Is there some other process already connected to the pipe? How would I check that? If there is, how can I also connect to the device with a pipe at the same time?

0 Answers
Related