[英]How can i close the visual studio code window with a python command?
i was writing a python script and i got the idea of making a line of code that closes the visual studio code window is there a way to do this with "just" python commands or do you need an other language for this?我正在编写一个 python 脚本,我想到了制作一行代码来关闭 Visual Studio 代码 window 有没有办法用“只” python 命令来做到这一点,或者你需要其他语言吗?
Yes, you can use psutil
是的,您可以使用
psutil
import psutil
for proc in psutil.process_iter():
if proc.name() == "Process name to kill" : # You can use some regex here too
proc.kill()
Name of the process can depend on platform you work on but if you list all processes with eg ps -A
(or by printing them with psutil) you should be able to find Visual Studio process name.进程的名称可能取决于您使用的平台,但如果您使用例如
ps -A
列出所有进程(或使用 psutil 打印它们),您应该能够找到 Visual Studio 进程名称。
Assuming you're working on Windows..假设您正在研究 Windows..
import os
os.system("taskkill /f /im code.exe")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.