How do I prevent my Powershell terminal from closing when I press CTRL-C after launching it from a .ps1 script

I’m running the following script in Powershell:

start powershell @'
    $Host.UI.RawUI.BackgroundColor = "red"
    $Host.UI.RawUI.ForegroundColor = "black"
    [console]::WindowWidth=100;
    [console]::WindowHeight=30;
    Clear-Host
    cd application1backend
    npm run start
'@

start powershell @'
    $Host.UI.RawUI.BackgroundColor = "blue"
    $Host.UI.RawUI.ForegroundColor = "white"
    [console]::WindowWidth=100;
    [console]::WindowHeight=30;
    Clear-Host
    cd application2backend
    npm run start
'@

start powershell @'
    $Host.UI.RawUI.BackgroundColor = "yellow"
    $Host.UI.RawUI.ForegroundColor = "black"
    [console]::WindowWidth=100;
    [console]::WindowHeight=30;
    Clear-Host
    cd application3backend
    npm run start
'@

This opens 3 new Powershell terminals and runs 3 different node applications (one per terminal).

It works fine except that when I kill the node application by hitting ctrl-c, it closes the terminal.

How can I keep the terminal open after hitting ctrl-c such that I can interact with it as I would a normal Powershell terminal that I opened manually?

Things I’ve tried:

  • Added Read-Host to the end of each script block. This doesn’t work because while it awaits user input after hitting ctrl-c (thus not closing the terminal), it closes the terminal as soon as I enter input.
  • Added [console]::TreatControlCAsInput = $true to the beginning of each script block. This prevents ctrl-c from working at all, so I can’t terminate the node applications.
  • Added -NoExit after start powershell on each script block but this just throws an error.

Any insight would be much appreciated. Thanks!

I’m on Windows 10.