1

I'm trying to automate checking what the current power plan is and then return a response based on that. Here's what I have:

import subprocess

plan = subprocess.call("powercfg -getactivescheme")
if 'Balanced' in plan:  
    print Success

When I run this I get "TypeError: argument of type 'int' is not iterable"

Can someone please tell me what I'm doing wrong here?

Steve Smith
  • 168
  • 2
  • 10

1 Answers1

2

subprocess.call returns a code, which means the status code of the executed command.

I also recommend you calling subprocess like this:

subprocess.call(["powercfg", "-getactivescheme"])

As I guess you want to get the output in a variable I recommend you using subprocess.check_output which returns a string containing the output of a command:

output = subproccess.check_output(["powercfg", "-getactivescheme"])

Then you can do the checking:

if 'Balanced' in output:  
    print 'Success'

Hope it helps,

avenet
  • 2,894
  • 1
  • 19
  • 26