简体   繁体   English

windows上的远程powershell脚本没有通过linux中的python脚本运行

[英]remote powershell scripts on windows not running through python script in linux

I have a python script written using paramiko and pysphere.this script is in linnux box.i have some powershell scripts on windows machine which i have to run one after the other(after each script ends obviously),but the point here is through my pythonscript it is not running the powershell scripts on windows machine.Kindly help. 我有一个使用paramiko和pysphere编写的python脚本。这个脚本在linnux box.i在windows机器上有一些powershell脚本,我必须一个接一个地运行(在每个脚本显然结束之后),但这里的重点是通过我的pythonscript它没有在Windows机器上运行powershell脚本。请帮助。 PS;i have to run python script fromlinux and powershell scriupts on windows. PS;我必须在windows上运行python脚本fromlinux和powershell scriupts。 Here is a snippet of code for running powershell scripts: 以下是运行powershell脚本的代码片段:

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

I doubt whether subprocess will work. 我怀疑子进程是否有效。

Please note that the bold prints given above are giving the correct script to run.there are many powershell scriptsinside the fo;der,so looping throught it and running each one of them. 请注意,上面给出的粗体打印正在运行正确的脚本。在fo; der中有许多powershell脚本,因此循环遍历它并运行它们中的每一个。

Any help would be appreciated,this thing is eating my heads off.....argghhhhhhhh.. 任何帮助将不胜感激,这件事正在吃我的头..... argghhhhhhhh ..

Cheers, NJ 干杯,新泽西州

I run powershell commands directly using paramiko: 我使用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()

Here 10.10.0.2 is my windows machine. 这里10.10.0.2是我的Windows机器。 Using cygwin sshd server for ssh. 使用cygwin sshd服务器进行ssh。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM