0

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.

5
  • 1
    can you provide the exact error you're getting? Is the error a Windows error or a Python error? Also you may want to use the subprocess module instead of os.system. Commented Apr 23, 2015 at 13:29
  • @notorious the error I get is shown in the Python script window, there is no trace back it only says "> was unexpected at this time." when it executes the command Commented Apr 23, 2015 at 13:32
  • @bladexeon I hope you are aware that you have posted the password in your python code! ;-) Commented Apr 23, 2015 at 13:35
  • The /pid argument should be an integer value. You may use /img for an image name of the process. microsoft.com/resources/documentation/windows/xp/all/proddocs/… Commented Apr 23, 2015 at 13:40
  • @pss But I have used the name of the process in a normal Windows cmd prompt and it worked saying "Process xxx has been killed" or something like that so I know this will work Commented Apr 23, 2015 at 13:41

1 Answer 1

1

Try something like the code below:

from subprocess import call

call(['taskkill', '/s', connection[i], '/u', 'CORP\Administrator', '/py',
      'CLARiiON!', '/pid', 'AxAuto.exe'])
Sign up to request clarification or add additional context in comments.

5 Comments

This one gave me: raise TypeError("This object does not support enumeration")
This may be caused by connection. What do you get when you print connection[i]
Aha! gives me this: <_wmi_namespace: ,COMObject <unknown>>> this coming from a different part of the code...also being ssomething i have no idea how to fix
I don't think you need to "fix" it, you just need to figure out how to get the IP address from that object or even if it's possible.
I figured out the error I was using a WMI connection variable instead of the raw IP variable, and It did work with Subprocess. Thanks Much!

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.