batch-filevisual-studio-code

When opening vscode using batch file, cmd opens and doesn't close


When trying to open vscode folder using a batch file, Visual Studio opens up with that folder, but also a cmd window pops up and does not go away if you use exit command.

@echo off
start code "C:\GitHub\TestApp\testapp"
exit 

VSCode opens up correctly, but also this window opens

cmd window


Solution

  • That CMD window is associated with the VSCode instance that you just opened. Attempting to close it will terminate the application you started. (in this case, VSCode)

    The start xxx xxx... command opens up a new cmd terminal to perform its action. Even though a new prompt appears, which can be used as a normal terminal itself, the VSCode process is inexorably linked to it as the parent process.

    If your goal is to not launch a separate cmd window, then run:

    start code /b "C:\GitHub\TestApp\testapp"

    which just runs the command in the same window. The VSCode window is still inexorably bound to the current cmd window and will close if the cmd window disappears, but at least another cmd window isn't launched.

    Windows doesn't have the capability to launch a program in the background from the terminal.