简体   繁体   中英

How to exit PowerShell.exe inside of CMD

In the command prompt, entering PowerShell.exe will start a PowerShell interactive prompt inside of cmd .

How can one exit this and return to cmd.exe ? Neither ctrl+c , exit() , nor the break button work.

Ctrl-Break works.

exit() might work, but calling functions with parentheses is not PowerShell syntax, so it's trying to use () as a function parameter, but () is not anything in PowerShell so it's that which generates the error message. exit(1) works, because (1) is a valid expression itself which evaluates to 1 so this is the same as exit 1 , and this command sets the %ERRORLEVEL% return value in the cmd environment.

It's described in help about_Language_Keywords :

Exit

Causes Windows PowerShell to exit a script or a Windows PowerShell instance.

When you run 'powershell.exe -File ', you can only set the %ERRORLEVEL% variable to a value other than zero by using the exit statement.

正确的命令是exit ,这将退出当前的 PowerShell 提示符并返回到cmd.exe

stop-process -Id $PID完全关闭 powershell 窗口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM