I'm working on a PowerShell script where I use rclone to mount remote file shares. The key commands I've been using include Start-Process with parameters like -PassThru and -NoNewWindow, but I'm having an issue. I thought Start-Process would allow the child process to run independently, so the parent can close without affecting it. However, when I run my script, the parent window stays open indefinitely, and if I close it, the rclone task gets killed too. Is there something I'm misunderstanding about how Start-Process works? Also, I found out from comments that I should be using -WindowStyle Hidden instead of -NoNewWindow. Can someone confirm this?
4 Answers
Just a heads-up; if you run a detached process and then close the parent PowerShell window, it can lead to unpredictable results. If the child process stays alive, good luck managing it. Just keep in mind how terminating parents might impact child processes. It's something to consider if your script isn't running under supervision.
You're correct about the -NoNewWindow parameter being the culprit. When you use that, it keeps the new process tied to your current PowerShell session. If you want a truly detached process, try removing that parameter and see how it behaves.
Exactly! The -NoNewWindow option prevents your script from detaching from the parent process. Switching to -WindowStyle Hidden should help in running your script without a visible window, which is what you need for detachment.
You might also want to consider removing the -PassThru argument. This is trying to send output back to your terminal, which might cause it to wait for completion. Removing it might help in closing the parent window without killing the child process.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically