简体   繁体   English

从 Python shell 脚本打开 VSCode

[英]Open VSCode from Python shell script

I'm trying to make a C++ project manager with Python in Ubuntu 22.04.我正在尝试在 Ubuntu 22.04 中使用 Python 制作 C++ 项目经理。

I'm trying to open VSCode from python using the following lines:我正在尝试使用以下行从 python 打开 VSCode:

subprocess.run(["cd", project_dir], shell=True)
subprocess.run([utility.get_ide_cmd()], shell=True)

This runs without error, but does not open VSCode.这运行没有错误,但不会打开 VSCode。
utility.get_ide_cmd() returns 'code .' utility.get_ide_cmd() 返回“代码”。

project_dir is the directory we want to open. project_dir 是我们要打开的目录。

I'm running the python script by calling it from a bash script with python3 <name> <args> .我通过使用python3 <name> <args>从 bash 脚本调用它来运行 python 脚本。

How do I open VSCode this way?如何以这种方式打开 VSCode?

Kind of dumb of me.我有点傻。

Because Subprocess is its own shell, using cd then code in another shell is worthless.因为 Subprocess 是它自己的 shell,所以在另一个 shell 中使用 cd then code 是没有价值的。 Using code project_dir works.使用code project_dir有效。

Thanks to @Charles Duffy感谢@Charles Duffy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM