Friday, 15 January 2010

python 2.7 - subprocess.popen(replacing a parameter from a list and place it on a command) -



python 2.7 - subprocess.popen(replacing a parameter from a list and place it on a command) -

it's first week python, apologize in advance if question sounds stupid.

basically wrote code:

__author__ = 'houssam' import subprocess subprocess import popen, pipe check = subprocess.popen(["winexe", "--system", "-u","mydomain\\myusername%mypassword", "//computername", "cmd /c c:\\windows\\system32\\inetsrv\\appcmd list site"],stderr=subprocess.pipe, stdout=subprocess.pipe) (stdout,stderr) = check.communicate() if check.returncode == 0: print 'iis installed on scheme in location below:' print stdout elif check.returncode == 1: print 'iis not installed on scheme ' , stderr

so can query iis of specific computer "//computername" , works.

however have 20 computers. want create list list = [computer1,computer2,computer3] , have function does: each c in list replace name of computer unique parameter "//computername" within subprocess.check_output calls winexe command don't have write command computers have.

i appreciate help , suggestions.

thank you,

houssam

i found answer:

i created list of servers

servers = [//computer1", "//computer2"]

then added statement , set list within popen follow:

server in servers: check= subprocess.popen(["winexe", "--system", "- u","mydomain\\myusername%mypassword", server, "cmd /c c:\\windows\\system32\\inetsrv\\appcmd list site"],stderr=subprocess.pipe, stdout=subprocess.pipe) (stdout,stderr) = check.communicate() if check.returncode == 0: print 'iis installed on scheme in location below:' print stdout elif check.returncode == 1: print 'iis not installed on scheme ' , stderr

then set in function follow:

def iis_check(servers): server in servers: check= subprocess.popen(["winexe", "--system", "- u","mydomain\\myusername%mypassword", server, "cmd /c c:\\windows\\system32\\inetsrv\\appcmd list site"],stderr=subprocess.pipe, stdout=subprocess.pipe) (stdout,stderr) = check.communicate() if check.returncode == 0: print 'iis installed on scheme in location below:' print stdout elif check.returncode == 1: print 'iis not installed on scheme ' , stderr

python-2.7 parameters subprocess popen winexe

No comments:

Post a Comment