0

Python を使用するのは初めての週なので、私の質問がばかげているように聞こえる場合は、事前にお詫びしたいと思います。

基本的に私はこのコードを書きました:

__author__ = 'houssam'

import subprocess
from 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 is installed on this system in the location below:'
print stdout


elif check.returncode == 1:
print 'IIS is NOT installed on this system ' and stderr

したがって、基本的に、特定のコンピューター「//computername」の IIS を照会することができ、それは機能します。

しかし、私は20台のコンピュータを持っています。list list = [computer1,computer2,computer3] を作成し、次のような関数を作成します。リスト内の c ごとに、コンピューターの名前を subprocess.check_output 内の唯一の一意のパラメーター「//computername」に置き換えます。 winexe コマンドを呼び出すので、所有しているすべてのコンピューターに対してコマンドを記述する必要はありません。

あなたの助けと提案に感謝します。

ありがとうございました、

ハウサム

4

1 に答える 1

0

私は実際に答えを見つけました:

サーバーのリストを作成しました

サーバー = [//computer1", "//computer2"]

次に、for ステートメントを追加し、次のように popen 内にリストを配置しました。

   for 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 is installed on this system in the location below:'
         print stdout


       elif check.returncode == 1:
         print 'IIS is NOT installed on this system ' and stderr

次に、次のように関数に入れます。

 def iis_check(servers):
    for 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 is installed on this system in the location below:'
            print stdout


         elif check.returncode == 1:
            print 'IIS is NOT installed on this system ' and stderr
于 2014-07-02T20:09:51.447 に答える