【发布时间】: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