Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Visual Studio Code through PowerShell and close PowerShell right after starting VSCode?

I would like to open Visual Studio Code for a specific folder, the command works I try to run, but when the script opens VSCode, it doesn't close the PowerShell window. I would like to close the PowerShell window right after the Script opens the VSCode. But even an explicit exit call does not work:

ii F:\c#
iex "& code ."
exit

This opens VSCode, but the Shell Window stays open until I close VSCode.

like image 640
Ray Yago Avatar asked Aug 03 '19 05:08

Ray Yago


1 Answers

This is the bug in the VS Code's backend. It unnecessary attaches itself to the console window preventing it to close even after shell application quit.

It actually not related to PowerShell. You will get the same behavior with .bat/.cmd file, which contains single code command. If you double-click it in explorer, then console windows will not close until you close VS Code, even though in task manager you can see, that CMD instance used to execute .bat/.cmd file no longer exists.

To workaround this bug you can create new hidden console window for VS Code to attach to, instead of console window of your PowerShell instance:

Start-Process -WindowStyle Hidden code .
like image 57
user4003407 Avatar answered Nov 15 '22 09:11

user4003407