Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exit Command Prompt after launching VSCode

Here are the steps to reproduce the problem:

  1. Open Command Prompt. ( cmd )
  2. Run code . to launching VSCode.
  3. Type exit and hit Enter in the Command Prompt.
  4. Then the Command Prompt is just paused. I have to wait VSCode exit to let Command Prompt window closed.

enter image description here

Does anyone know why? How can I close Command Prompt window without exiting VSCode?

like image 219
Will Huang Avatar asked Jun 15 '18 19:06

Will Huang


People also ask

How do I get out of terminal VSCode?

Hitting Esc clears out the terminal and cancels everything.

Can you pop out terminal in VSCode?

Use the Ctrl+` keyboard shortcut to toggle the terminal panel. Use the Ctrl+Shift+` keyboard shortcut to create a new terminal.


3 Answers

I found a solution here: https://github.com/Microsoft/vscode/issues/6608. It involves changing the code.cmd file (usually found under "C:\Users\yourUsername\AppData\Local\Programs\Microsoft VS Code\bin").

Changing the fifth line in that file from

call "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*

to

start "" "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*

will make the cmd window close right away. But that change will apparently break some other things (specifically the --wait flag), so I figure it's wiser to leave the code.cmd file alone.

Instead I made a copy ("codeNoCommandPrompt.cmd") right beside it and changed the line in there. That works fine for my usecase, namely having VS Code start on a specific folder alongside a bunch of other programms via a script.

like image 100
Niki Herl Avatar answered Nov 03 '22 02:11

Niki Herl


I just tested it (using the latest VSCode 1.24.1), and it does work: the CMD shell session closes immediately when typing "exit".

Try calling the code.cmd script with its full path to see if the issue persists:

"C:\Program Files\Microsoft VS Code\bin\code.cmd" .

Try also the same command after having simplified the PATH (for testing)

set PATH=C:\Program Files\Microsoft VS Code\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
code .
like image 33
VonC Avatar answered Nov 03 '22 00:11

VonC


Simply use this

code . && exit

like image 27
Utsav Barnwal Avatar answered Nov 03 '22 01:11

Utsav Barnwal