#🔒 Can't open vscode from python subprocess on windows
46 messages · Page 1 of 1 (latest)
@safe palm
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.
e.g. subprocess.run(['code']) doesn't work
subprocess.Popen(['code'])neither. Both fails with not found
Sorry i don't speak (french?)
Le fichier spécifié est introuvable
I have no idea what error is trying to say
I'd take a guess that code isn't in the path and you would need to specify the full path of the executable
sorry it says file not found
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
but that's weird because in cmd I can call code
even !code in ipython works
If I remember correctly, I'll have to double check the docs it has a separate environment
Oh, thanks
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']
try shell=True
oh nice, it works
The warning here covers it: https://docs.python.org/3/library/subprocess.html#subprocess.Popen
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
yes I was confused bc I also use a custom executable which worked
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
My guess is that your custom executable have a relative path instead of being in PATH
that makes sense, ty very much!
and thx rand for the doc
You're welcomed (no idea how to say this in french)
"de rien"
Nice, might learn some now that I live close to France
Using shell=True generally isn't a good idea without understanding the security side effects - https://docs.python.org/3/library/subprocess.html#security-considerations
Oh I have no idea
oh good to know
This would be considered safer -
import subprocess, os
env_copy = os.environ.copy()
subprocess.Popen("code", env=env_copy)
No idea if this work
I see, thx
Is shell safety only a problem in window
It seemes to not mention linux
Oh, no I think it's unsafe everywere
It applies to Linux, more so, as it is easier to manipulate imo
huh so this is what happened with the rust "cve"
Thanks
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.