Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to prevent being connected to named pipe on Windows platform? #1038

Open
nagok opened this issue Apr 8, 2024 · 0 comments
Open

Comments

@nagok
Copy link

nagok commented Apr 8, 2024

On Windows platform '\\.\pipe\' directory can be monitored to catch the creation of named pipes.

When the following program is executed, the connection to the named pipe should not be processed, but the connection is made at the point of creation of the named pipe on the server process side, resulting in an error within the waiting process of the server process.

class PipeCreateEventHandler(FileSystemEventHandler):
    def on_created(self, event):
        print(f"on_created: {event.src_path}")
        if event.src_path == r'\\.\pipe\mypipe':
            observer.stop()

observer = Observer()
observer.schedule(PipeCreateEventHandler(), r'\\.\pipe''\\', recursive=False, event_filter=[FileCreatedEvent])
observer.start()
observer.join()

# Do something using '\\.\pipe\mypipe'

Perhaps the os.path.isdir() call in read_directory_changes.py is the cause.

                elif winapi_event.is_added:
                    isdir = os.path.isdir(src_path)

For reference, here is a server program for testing with PowerShell.

echo "Create mypipe"
$pipe = New-Object System.IO.Pipes.NamedPipeServerStream "mypipe", InOut

echo "WaitForConnection"
$pipe.WaitForConnection()    # MethodInvocationException raised

echo "Connect"

# Do something using '\\.\pipe\mypipe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant