Search code examples
pythonvisual-studio-codesubprocesspopen

Excecute subprocess.Popen() from VSCode to open another instance of VSCode


I am using the following line of code to open VS Code (regular version) from Spyder or VS Code Insiders:

import subprocess
p = subprocess.Popen(["C:/Users/username/AppData/Local/Programs/Microsoft VS Code/code.exe"])

It works perfectly fine this way.

However, if I want to execute the line from VS Code to open another instance of VS Code, it does not work. Meaning, it basically does nothing.

I only works when I modify it as follows:

p = subprocess.Popen(["code"], shell=True)

What do I miss here?


Solution

  • Try using the --new-window flag, otherwise VS Code is probably reusing the running instance.