简体   繁体   English

如何使用 python 命令关闭 Visual Studio 代码 window?

[英]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.

相关问题 如何在 Visual Studio Code 中调试 Python 3 代码? - How can I debug Python 3 code in Visual Studio Code? 如何在python(类)中发出命令以打开第二个 window 并关闭主 window - How can I make a command to open second window and close the main window in python(class) 如何从Python打开Visual Studio代码? - How can I open visual studio code from Python? 如何创建 Visual Studio Code Python 工作区? - How can I create a Visual Studio Code Python workspace? 如何在 Visual Studio Code 中更改 Python 版本? - How can I change the Python version in Visual Studio Code? 我如何在 python Visual Studio 代码中使用我的 GPU - how can i work with my GPU in python Visual Studio Code 在Visual Studio(PTVS)的Python工具中调试python代码时,如何禁止控制台窗口? - How do I suppress the console window when debugging python code in Python Tools for Visual Studio (PTVS)? 如何在执行代码时打开或关闭Visual Studio python(Jupyter)交互式窗口(2019)? - How do i turn on or off the Visual Studio python (Jupyter) interactive window (2019) when executing code? 如何使用超级用户权限或 root 权限在 Visual Studio Code 中启动 python? (即使用 sudo 命令) - How to launch python in Visual Studio Code with superuser permission or root permission? (i.e. using sudo command) 如何在 Visual Studio 代码交互式 window 中编辑单元格 - How do I edit a cell in visual studio code interactive window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM