Kyle Me
Kyle Me

Reputation: 336

How can I exit a program (not python script) from Python 3?

I am currently working on a program that will back up my Skype and iTunes data. It works fine with my iTunes data, however, when I try to backup files from Skype I get loads of errors. These are caused from the program still being open.

I thought it would be a fun little project to try and find out how to force quit a program (and then re-open).

I have successfully learned how to OPEN Skype (with a simple statement,

import os
os.startfile(path) #this opens programs. I need to close. 

So I think to get my program to work, all I would need to do is close skype, run the backup process, then re-open it.

When I tried searching my question, I was only finding answers to close PYTHON scripts. I need to close something that is running in Windows.

Upvotes: 0

Views: 114

Answers (1)

Kyle Me
Kyle Me

Reputation: 336

I have found the answer.

import os
os.system("taskkill /im skype.exe") #/im means "ImageName"

taskkill is a command-line reference. "Ends one or more tasks or processes. Processes can be killed by process ID or image name" http://technet.microsoft.com/en-us/library/bb491009.aspx

Thank you @furas for leading me to the page with the answer. I'm surprised I missed it, I tried searching for a while.

Upvotes: 1

Related Questions