📌  相关文章
📜  在没有终端的情况下运行 python - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:46.367000             🧑  作者: Mango

代码示例1
import ctypes
import os
import win32process

hwnd = ctypes.windll.kernel32.GetConsoleWindow()      
if hwnd != 0:      
    ctypes.windll.user32.ShowWindow(hwnd, 0)      
    ctypes.windll.kernel32.CloseHandle(hwnd)
    _, pid = win32process.GetWindowThreadProcessId(hwnd)
    os.system('taskkill /PID ' + str(pid) + ' /f')
    
#this code will close the console window as soon as the code is run