I am trying to close the program, in this case spotify, but I am keep getting semantic mistake. Here is my code:
sup_programs.txt
{
'spotify': ['C:/Users/Daniiar/AppData/Roaming/Spotify/Spotify.exe']
}
script:
class Path(object):
import ast
sup_programs_txt = open('sup_programs.txt', 'r')
s_p = sup_programs_txt.read()
paths = ast.literal_eval(s_p)
sup_programs_txt.close()
paths = Path().paths
program_name = 'spotify'
def open_program(path_name):
import subprocess
subprocess.Popen(path_name)
open_program(paths[program_name])
def close_program(path_name):
import subprocess
p = subprocess.Popen(path_name)
p.terminate()
yes = input(" ... ")
if 'close' in yes or 'yes' in yes:
close_program(paths[program_name])
else:
print('too bad')
I used kill() and terminate() neither of them have worked and os.system('TASKKILL ') Is there any other methods or am using existing ones incorrectly?
BTW, I am using windows 10 and python 3.5 . Thank you for your help
p.terminate()on this p, not another instance of that executable.