1

I created a batch file to open VS Code to a specific folder. Here is the code -

cd z:\files\development\xampp\code\htdocs\Acme1
code .

Note that Z: maps to an external SSD. The above works as expected.

Then I added more lines to try and open multiple instances of VS Code -

cd z:\files\development\xampp\code\htdocs\Acme1
code .
cd z:\files\development\xampp\code\htdocs\Acme2
code .

I expected this to open 2 separate instances of VS Code, one with the Acme1 folder open, the other with the Acme2 folder open. However, it only opens VS Code once, with the Acme1 folder open.

Per this answer, I modified my Windows 11 Path environment variable to include C:\Users\knot22\AppData\Local\Programs\Microsoft VS Code\bin. Alas, this made no difference in the behavior of the batch file, even after restarting the machine.

What needs to be changed to get the batch file to open both instances of VS Code?

knot22
  • 2,648
  • 5
  • 31
  • 51
  • The Windows Command Processor `cmd.exe` always waits for self-termination of a started executable independent on being a Windows GUI or Windows console application on processing a batch file before it reads the next command line from the batch file and processes it. The batch file could contain just the two lines `@start "" "%LOCALAPPDATA%\Programs\Microsoft VS Code\bin\code.exe" --new-window "Z:\files\development\xampp\code\htdocs\Acme1"` and `@start "" "%LOCALAPPDATA%\Programs\Microsoft VS Code\bin\code.exe" --new-window "Z:\files\development\xampp\code\htdocs\Acme2"`. – Mofi Feb 06 '23 at 13:50
  • Please read [The Visual Studio Code command-line interface](https://code.visualstudio.com/docs/editor/command-line). Then open a command prompt window and run `start /?` to get output the usage help of this [Windows command](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) which results in calling the Windows kernel library function [CreateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) always used by `cmd.exe` to run an executable without waiting for self-termination of EXE. – Mofi Feb 06 '23 at 14:07
  • A batch file is not needed for that task. A shortcut file (`.lnk` file) like those on Windows __Desktop__ or in Windows __Start__ menu does the same with property __Target__ being configured with: `%SystemRoot%\System32\cmd.exe /S /D /C "start "" "%LOCALAPPDATA%\Programs\Microsoft VS Code\bin\code.exe" --new-window "Z:\files\development\xampp\code\htdocs\Acme1" & start "" "%LOCALAPPDATA%\Programs\Microsoft VS Code\bin\code.exe" --new-window "Z:\files\development\xampp\code\htdocs\Acme2""` – Mofi Feb 06 '23 at 14:07

1 Answers1

1

This is how you open multiple vscode instances with batch

code your_first_path & code your_second_path & code your_third_path etc.

so in your case this is how you open both folders with vscode

code z:\files\development\xampp\code\htdocs\Acme1 & code z:\files\development\xampp\code\htdocs\Acme2

alternatively you can open multiple vscode instances this way

cmd /c code your_first_path
cmd /c code your_second_path 
cmd /c code your_third_path etc.
mmh4all
  • 1,612
  • 4
  • 6
  • 21
  • 1
    Both options work. I really like the second option, listing one path per line, for the sake of readability. – knot22 Feb 06 '23 at 14:07