Run file with default, then kill later

I've been working on something that can run a file with the default app for that file, so executing a .exe, but opening a .txt with notepad, for example.

I am currently using the crate 'opener'. It does what I want, but it just returns the result.
I want to also be able to kill the process later, how would I combine (std::Command::Child).kill with opener?
Or is there a better way?

Thank you

It does not look like it is possible to get any information about the child process from the opener crate. There is a different crate called open which provides access to a std::process::Command: commands in open - Rust That can in turn be used to spawn and gain access to a Child handle.

1 Like

Thank you, that works well.
I only have one issue: "Access is denied. (os error 5)" is thrown by child.kill()

How can I avoid this? I'd rather not require opening with administrator every time.



And even if you could, you shouldn't use it, because depending on the platform (e.g. macOS), the file might be displayed by an existing process, so killing it would be harmful to the user's other work.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.