1

I have a Linux python app, that runs a web php app on a server, that requests data from a MySql database and saves the answer in a text file on the server. I can download the text file from the server using pysftp however ... I have to manually close the web app. Then I start another python app passing the text file data to it.

I can't find find a way to close the web app using code. I like w3m because it runs from the terminal. I can close it using Shift+Q. I can close with the cap locks on and pushing Q so it doesn't require two keys. But I can't find a way to send Shift+Q programmatically. I have also tried and can run Firefox, and Chrome from python but can't find a way to close them using code in my php app or python app either.

I have tried the obvious:

<?php echo chr(81); ?>
General Grievance
  • 4,555
  • 31
  • 31
  • 45
gerardg
  • 203
  • 2
  • 9

1 Answers1

1

if your web app is running on a browser:

There is no webbrowser.close, you can use these codes to close the task(in Windows OS):

First Import os package with

import os

then use system function to kill the task

os.system("taskkill /im firefox.exe /f") os.system("taskkill /im chrome.exe /f")

For MacOS, you can use below command:

os.system("killall -9 'Google Chrome'")

source: How to close web browser using python

  • 1
    `killall -9` is bad, it will close all instances of chrome being used by other apps too. A better way could be to kill browser-instance (tab) specifc pid. – vish4071 Dec 17 '21 at 05:51