0

I want to use terminal script to open both of my working folders using VS code at once. I'm currently using this

@echo off

start code "path to folder 1"
start code "path to folder 2"

While this does open both folders in VS code at once it also open 2 terminals. Is there anyway for me stop those terminals from opening and only have VS code windows open?

2
  • Yes, that is possible with not using a batch file with file extension .cmd (or .bat), but a shortcut file with file extension .lnk. The usage of the shortcut file results in starting code.exe by explorer.exe by calling the the Windows kernel library function CreateProcess without opening a console window at all because of code.exe is a Windows GUI application and not a Windows console application like cmd.exe processing the batch file. Commented Jun 22, 2024 at 9:50
  • I recommend reading this answer. There is explained in full details how to run Visual Studio Code with a folder path with using a shortcut file or with using a registered open context menu item for directories. It is unclear for me if you want to start two Visual Studio Code processes each with a specified folder path or start just one Visual Studio Code process with a multi-root workspace by passing two folder paths to code.exe on startup. Commented Jun 22, 2024 at 9:57

1 Answer 1

0

if you don't want an additional CMD-Window to appear, use the /B option and rename your .Bat to .cmd. Is that what you need?

@echo off
start /B code "path to folder 1"
start /B code "path to folder 2"
Sign up to request clarification or add additional context in comments.

5 Comments

Why does the name of the file matter?
@user1934428, it's not the name itself. It's the file-extension. Please have a look here. THe difference is explained in both answers stackoverflow.com/questions/5347593/…
In the question you linked, it turned out that - for the extension - the difference is how the error level is set. Also, if we can believe the accepted answer there, a difference is whether command.com or cmd.exe is running the file. Even if this were true (I doubt it a), this does by itself not explain, why the difference is relevant for the OPs question.
in fact the script from my answer will only work within a .cmd-file. If you put it into a .bat, it will only launch the first VS window. If anyone can explain the reason behind, please feel free to comment. I'd like to know, too. The OP asked for a way to open both windows from a script. Thats what my answer explains.
Windows is really bizarre sometimes...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.