#🔒 Can't open vscode from python subprocess on windows

46 messages · Page 1 of 1 (latest)

safe palm
#

I get an erro whatever I try (run, Popen etc)

acoustic geyserBOT
#

@safe palm

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

safe palm
#

e.g. subprocess.run(['code']) doesn't work

#

subprocess.Popen(['code'])neither. Both fails with not found

quaint halo
#

Sorry i don't speak (french?)

#

Le fichier spécifié est introuvable

#

I have no idea what error is trying to say

fluid coyote
safe palm
fluid coyote
#

Can you open cmd and type code and have it open? If not, then it'll need to either a) be added to the path or b) use the fully qualified path

safe palm
#

even !code in ipython works

fluid coyote
quaint halo
safe palm
#
In [7]: import sys

In [8]: sys.path
Out[8]:
['C:\\Users\\Travail\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\ipython.exe',
 'C:\\Users\\Travail\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip',
 'C:\\Users\\Travail\\AppData\\Local\\Programs\\Python\\Python312\\DLLs',
 'C:\\Users\\Travail\\AppData\\Local\\Programs\\Python\\Python312\\Lib',
 'C:\\Users\\Travail\\AppData\\Local\\Programs\\Python\\Python312',
 '',
 'C:\\Users\\Travail\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages']
quaint halo
#

try shell=True

safe palm
fluid coyote
quaint halo
#

If you want to you can pass env individually I think

#

But shell=True use your default system shell, so PATH would be set by default

safe palm
#

but this executable is in the same folder as my python script

#

which is probably why it was able to find it and not code

quaint halo
safe palm
#

and thx rand for the doc

quaint halo
#

You're welcomed (no idea how to say this in french)

quaint halo
#

Nice, might learn some now that I live close to France

fluid coyote
quaint halo
#

Oh I have no idea

quaint halo
#

Use env={"PATH":sys.path}

#

Try this

fluid coyote
#

This would be considered safer -

import subprocess, os

env_copy = os.environ.copy()
subprocess.Popen("code", env=env_copy)
quaint halo
#

No idea if this work

safe palm
#

I see, thx

quaint halo
#

It seemes to not mention linux

#

Oh, no I think it's unsafe everywere

fluid coyote
#

It applies to Linux, more so, as it is easier to manipulate imo

quaint halo
#

huh so this is what happened with the rust "cve"

acoustic geyserBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.