Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6352771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:17:11+00:00 2026-05-24T22:17:11+00:00

I had the tskill operation working fine through a python script when using Python

  • 0

I had the tskill operation working fine through a python script when using Python 2.7 but when I switched to 2.5 this code fails.

import os
import time
import win32com.client
os.startfile('cmd')
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate('Administrator:C:\Windows\System32\cmd.exe')
time.sleep(2)
shell.SendKeys('tskill java + {ENTER}')
time.sleep(2)
shell.Sendkeys('tskill javaw + {ENTER}')
#shell.SendKeys('exit + {ENTER}')

I use os.startfile to run a python script that opens and runs the application(It’s a graphics tool).

Note: The application is already running by the time this script is called, hence I don’t need to open it here.

Can some one please tell me how to close an application successfully using this or similar method on Python 2.5. Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:17:11+00:00Added an answer on May 24, 2026 at 10:17 pm

    I don’t have tskill on my system, but I think it’s similar to taskkill /F /FI "IMAGENAME eq java*". Anyway, here’s how to call a normal console application in the background (i.e. a hidden window) using the subprocess module (tested in Python 2.5.2, but using taskkill instead):

    import subprocess
    
    def tskill(*args):
        si = subprocess.STARTUPINFO()
        si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        command = ('tskill',) + args
        rc = subprocess.call(command, startupinfo=si)
        return rc == 0
    
    if tskill('java') and tskill('javaw'):
        #success
    

    I used call because it only matters whether the call succeeds or fails, but in general you can use subprocess.PIPE to capture stdout and stderr using subprocess.Popen.

    Edit: How to kill a process started with the subprocess module

    command = ['path/to/executable', 'arg0', 'arg1', '...']
    p = subprocess.Popen(command)
    #do something
    
    #kill if it's still alive
    if p.poll() is None: 
        p.kill()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this simple modal contact form working fine but must have broke it
Had this working well in Emacs 23.1.x but it appears to have broke in
Had a page that was working fine. Only change I made was to add
I had some sample code I was working on and broke the link to
Had a good crack at this, quite a few articles around but I can't
I had this setting in my php.ini file: error_reporting = E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR But I was
I had everything working great in 1.4.0.2 but updated to 1.6.0.0 and now I
Had a coworker ask me this, and in my brain befuddled state I didn't
I had an idea, if I add a python .py file to my C#
Had this question in an interview.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.