Search code examples
powershellcommand-prompt

Stop auto-close of command prompt, that were started in PowerShell


I have a PowerShell script:

Start-Process -FilePath 'dotnet' -WorkingDirectory [Directory] -ArgumentList 'build'
Write-Output "starting: Main application " 

That script is in a foreach which iterates directories. It opens a command prompt window and runs in each directory. After it's finished it closes the command prompt.

I would like that the command-prompt window remains open after execution.

Many similar questions answers with 'use pause' or 'use /k'

But how do I add this to my script?

I've tried:

Start-Process -FilePath 'dotnet' -WorkingDirectory [Directory] -ArgumentList 'build /k'
Write-Output "starting: Main application " 

Start-Process -FilePath 'dotnet' -WorkingDirectory [Directory] -ArgumentList 'build & pause'
Write-Output "starting: Main application " 

And many other variation. I don't know how to pass the command


Solution

  • Thanks to PetSerAl it's:

    Start-Process -FilePath 'cmd' -WorkingDirectory [Directory] -ArgumentList '/k dotnet build'