有时候需要Python不能完成一些功能时,需要用到PowerShell的脚本,但是想要完成一个完整性功能,就需要在Python执行完会直接调用PowerShell脚本,以下举个例子来实现这个功能。
先写一个PowerShell的脚本:
#通过Python函数传进来的iplist进行Ping测试,并返回结果 function test_ping($iplist){ #$a = $iplist.split(",") foreach ($myip in $iplist) #foreach ($myip in $a){ $strQuery = "select * from win32_pingstatus where address = '$myip'" # 利用 Get-WmiObject 送出 ping 的查詢 $wmi = Get-WmiObject -query $strQuery if ($wmi.statuscode -eq 0) { echo "Pinging`t$myip...`tsuccessful" } else { echo "Pinging`t$myip...`tErrorCode:" + $wmi.statuscode } } } test_ping $args
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#通过Python函数传进来的iplist进行Ping测试,并返回结果
function
|