Steve Smith
Steve Smith

Reputation: 168

Confirm current power plan via python

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?

Upvotes: 1

Views: 697

Answers (1)

avenet
avenet

Reputation: 3043

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,

Upvotes: 3

Related Questions