bladexeon
bladexeon

Reputation: 706

Python executing commands in the command prompt (taskkill)

I'm trying to use os.system to use the taskkill command in command prompt. ill gut out the only part im having trouble with:

os.system('taskkill /s %s /u CORP\Administrator /p CLARiiON! /pid AxAuto.exe'%(connection[i]))

The variable connection[i] is just an IP Address of a remote computer on the same network. I can run this command straight from the command prompt locally and just directly input the IP and I know for a fact it will work, But running the command through Python in this format returns "> was unexpected at this time." Am I making a silly formatting mistake in this line of code? the error can be seen below: "> was unexpected at this time.


EDIT: I've also been told to use the Subprocess module. i tried the snippet below:

command="taskkill /s %s /u CORP\Administrator /p CLARiiON! /im AxAuto.exe"%(connection[i]))
subprocess.Popen(command, stdout= subprocess.PIPE, stdin = subprocess.PIPE, stderr=subprocess.PIPE)

It doesnt fail in the script but it also doesnt kill the process.

Upvotes: 0

Views: 2323

Answers (1)

notorious.no
notorious.no

Reputation: 5107

Try something like the code below:

from subprocess import call

call(['taskkill', '/s', connection[i], '/u', 'CORP\Administrator', '/py',
      'CLARiiON!', '/pid', 'AxAuto.exe'])

Upvotes: 1

Related Questions