【问题标题】:remote powershell scripts on windows not running through python script in linuxwindows上的远程powershell脚本没有通过linux中的python脚本运行
【发布时间】:2013-10-05 13:24:36
【问题描述】:

我有一个使用 paramiko 和 pysphere 编写的 python 脚本。这个脚本在 linnux 盒子里。我在 windows 机器上有一些 powershell 脚本,我必须一个接一个地运行(每个脚本显然结束之后),但重点在这里是通过我的 pythonscript 它没有在 Windows 机器上运行 powershell 脚本。请帮助。 PS;我必须在 Windows 上从 Linux 和 powershell 脚本运行 python 脚本。 这是运行powershell脚本的sn-p代码:

target_vm1 = connect_Esxi_Server(return_list[0])

print "Again connected to vm:" + return_list[0]

target_vm1.login_in_guest(vmUser,vmPass)

list_scripts = target_vm1.list_files(VM_SCRIPT_LOCATION)

for f in list_scripts:

    size = f['size']
    **if size <> 0:**

        paths = f['path']

        print paths

        #for all_scripts in paths:
        *****print "script running is :" , paths*****
        path_l = os.path.join(VM_SCRIPT_LOCATION + '\\'+ paths)
        *****print path_l*****
        run_script =            
subprocess.Popen([r'c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe',". path_l"], shell=True)

        result = run_script.wait()
        print "result is:", result

我怀疑子进程是否可以工作。

请注意,上面给出的粗体字给出了要运行的正确脚本。文件夹中有许多 powershell 脚本,因此循环遍历并运行每个脚本。

任何帮助将不胜感激,这东西正在吞噬我的脑袋.....argghhhhhhhh..

干杯, 新泽西州

【问题讨论】:

    标签: linux python-2.7 subprocess powershell-2.0 paramiko


    【解决方案1】:

    我直接使用 paramiko 运行 powershell 命令:

    import paramiko 
    
    ssh = paramiko.SSHClient()
    
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    
    ssh.connect('10.10.0.2', username='vipul', password='password')
    
    cmd = "powershell -InputFormat none -OutputFormat text echo Hello"
    
    stdin, stdout, stderr = self.ssh.exec_command(cmd)
    
    print stdout.readlines()
    

    这里 10.10.0.2 是我的 windows 机器。使用 cygwin sshd 服务器进行 ssh。

    【讨论】:

      猜你喜欢
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-25
      • 2011-11-01
      • 1970-01-01
      • 2013-04-11
      相关资源
      最近更新 更多