Stop Powershell from exiting

后端 未结 8 1905
傲寒
傲寒 2021-02-05 06:01

I know that there is that little -noexit switch for PowerShell.

Is there anyway of staying in the shell without using that switch?

In other words, I

8条回答
  •  名媛妹妹
    2021-02-05 06:44

    This script will not exit if you run it without arguments, e.g. by double-clicking on it:

    param($Work)
    
    # restart PowerShell with -noexit, the same script, and 1
    if (!$Work) {
        powershell -noexit -file $MyInvocation.MyCommand.Path 1
        return
    }
    
    # now the script does something
    # this script just outputs this:
    'I am not exiting'
    

提交回复
热议问题