python - My Mac network location script is broken -


i starting learn python , decided start though simple script guess not. want return current network location using on mac. every time run it, gives me correct location when try change it, nothing happens. don't know doing wrong here code. hope 1 can me. script unique macs btw. know "scselect" built in wanted see if done python. code below rough know learn make better. using python 2.7.

import subprocess  loc = "scselect" srn = "scselect srn" home = "scselect home"  = subprocess.check_output(loc, shell=true)  print "\n##### network selection #####" print "\nyour current location set \n\n%s" %  choice = raw_input("please select location want change to: ")  b = subprocess.popen(srn, shell=true, stdout=subprocess.pipe) c = subprocess.popen(home, shell=true, stdout=subprocess.pipe)  choice = int(choice)  if choice == 1:     print "\nswitching home...\n"     c elif choice == 2:     print "\nswitching srn...\n"     b else:     print "\nshutting down...\n" 

you run both scselect commands first, display output of 1 of commands.

by time come if choice == 1, etc. both b , c have been set , have captured output of commands. both scselect srn and scselect home have been run, last 1 undoing first command achieved.

move subprocess calls if statements:

if choice == 1:     print "\nswitching home...\n"     output = subprocess.popen(home, shell=true, stdout=subprocess.pipe)     print output 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -