1

I am not very familiar with the computer software terminology (my apologies).

  • I designed a GUI in Python that suppose to execute and/or terminate a script when an appropriate button (on the GUI) is pressed.
  • When I press a "Start" button (QPushButton) on the GUI, the following command executes the script filename.dut in the command prompt as follows:
    subprocess.call ('launcher.exe localhost filename.dut', shell=True).

  • I want to be able to terminate the script in a similar way, i.e., to press a "Stop" button on the GUI that will write into the command prompt an appropriate command to terminate the script. I think I can find the solution in this thread: Ending external programs with Python. The suggested solution is:

    import subprocess        
    taskname = '...'        
    task = 'taskkill /im ' + taskname + ' /f'         
    subprocess.check_call(task, shell=True)
    
  • My quastion is how can I obtain the taskname ?

Any suggestions or alternate solution would be very appreciated.

1
  • I've never used the subprocess module, but if you can get the process id, psutils looks like it might help. Commented Jul 30, 2013 at 20:04

1 Answer 1

1

If you use subprocess, you don't need to call any external utilities. subprocess.Popen class provides terminate method.

In order to use it, you'll need to replace subprocess.call(...) with subprocess.Popen(...), which returns a Popen instance. For example,

task = subprocess.Popen('launcher.exe localhost filename.dut', shell=True)
# some time later
task.terminate()

Note that, unlike call, plain Popen doesn't wait for process to complete.

Consult the manual for more details: http://docs.python.org/2/library/subprocess.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.