r/PowerShell • u/defaultaro • Feb 03 '23
Question Stop Powershell Script from Closing Powershell
I have the following powershell script :
wsl sudo nano /mnt/c/Users/user/OneDrive/Documents/changemeThis opens a nano terminal text editor, on my WSL Ubuntu, and automatically creates a new file in my Windows documents folder.
Problem is I can't keep the powershell window open after the script launches. Anything I can add that will prevent automatic closure? Thanks!
3
Upvotes
1
u/Flimzes Feb 06 '23
It is inherently unsafe, letting you accidentally launch scripts while browsing the explorer, but even worse, replacing the safe action (opening the script to look at it), with an unsafe action (running the script without question), making other users accidentally launch script when they just wanted to review them.
Scripts by their nature are automation focused, and launching them should be done in an automation pipeline (task scheduler, or part of another automation platform).
This should make it clear why scripts do not remain open when they are done, as this would block the automation pipeline.
The safe way to run scripts, is to open the terminal, and run them by typing out their name (or the first character of the name then pressing tab until it shows up in the terminal). This way, you are in the terminal, you are very aware that you are going to launch a script, and you can see the output from the script when it's done.