1

I'm trying to open two VSCode projects from a batch file, and then close the batch file and let the VSCode run.

Tried several methods:

This does not close the batch file, and if I close it by my self, VSCode terminates:

start "" "C:\Program Files\Microsoft VS Code\Code.exe" c:\project1
start "" "C:\Program Files\Microsoft VS Code\Code.exe" c:\project2
exit

This one opens two cmds, each one opens VSCode and then terminates, but often it also holds and does not close for some reason:

start cmd /c "code c:\project1 && exit"
start cmd /c "code c:\project2 && exit"

Simply running VSCode sometimes holds the execution of the next commands altogether:

code c:\project1
code c:\project2
.
.  <-- Next commands don't run
.

So how should I open VSCode in a way that will not stop the execution and will not depend on the terminal remaining open?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Poogy
  • 2,597
  • 7
  • 20
  • 35
  • have you tried without start? `cmd /c "code c:\project1 && exit" ` – Gerhard Apr 16 '18 at 11:41
  • Tried it now. Doesn't work. It continues executing all the next commands but does not exit from the main batch file even if there is an "exit" command – Poogy Apr 16 '18 at 13:11
  • Always put the (empty) pair of quotes behind `start`, like `start "" cmd /c ...`, because the first quoted string might be interpreted as a window title rather than something else... – aschipfl Apr 16 '18 at 16:49
  • @aschipf Tried it also, doesnt work – Poogy Apr 18 '18 at 07:53

2 Answers2

1

add call before

call code C:/proyect1
call code C:/proyect2

I've answer this in another post: The file run by "code ." is not really an executable but a .cmd/.bat. As discused in here. Running one batch script within another without call will stop execution

0

I know this topic is more than 2 years old now, but I was facing this problem right now and just found out the solution.

Try calling code.exe directly instead the code.cmd that is in system path.

"%localappdata\Programs\Microsoft VS Code\Code.exe" C:\project1
"%localappdata\Programs\Microsoft VS Code\Code.exe" C:\project2
exit