Python, Voice Assistant

58 Views Asked by At

I use "subprocess" to open a browser window using a voice assistant (in python). Actually, it opens. But how do I write code so that the browser closes with a certain command, for example, "close the browser"?

I use the following code:

if cmd == 'open_browser':  
        subprocess.call("explorer    C:\\Users\\Mandalorian\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe" , shell=True)
        play("ok")`

I have Windows 10, python 3.8.3

I've already tried it but it didn't help:

        time.sleep(1)
        os.kill(subprocess.pid, signal.SIGINT)` time.sleep(1)
        os.kill(subprocess.pid, signal.SIGINT)
and
        process = subprocess.Popen(cmd, shell=True)
        time.sleep(5)
        process.terminate()`
1

There are 1 best solutions below

0
mrithul e On

you can use pywindctl library- https://pypi.org/project/PyWinCtl/ for closing,minimizing,always on top mode, etc..