Skip to content

How to properly handle ctrl-C/SIGINT using PowerShell? #76

Description

@santo998

Hi! First of all, thanks for Shawl — it’s a really useful tool.

I noticed that the documentation says:

"Shawl is a wrapper for running arbitrary programs as Windows services, written in Rust. It handles the Windows service API for you so that your program only needs to respond to ctrl-C/SIGINT."

However, I couldn’t find concrete examples showing how to properly handle this in practice.

I think it would be especially valuable to include PowerShell examples, since scripts don’t typically run as Windows services and handling signals in that context is not very straightforward.

In my specific case, I have a PowerShell script running as a service that uses a loop with sleep intervals. I’d like to handle CTRL+C (SIGINT) in a clean and elegant way.

Right now, I had to implement a workaround where I split the sleep into 1-second intervals inside a loop, so the script can respond in time. Otherwise, Shawl ends up terminating the process because it doesn’t react quickly enough.

Is there a recommended pattern for handling this scenario properly, especially for PowerShell scripts?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions