Python 官方文档:入门教程 => 点击学习
# -*- coding: utf-8 -*- import subprocess def python_call_powershell(ip): try: args=[r"powershell",r"D:\j
# -*- coding: utf-8 -*-
import subprocess
def python_call_powershell(ip):
try:
args=[r"powershell",r"D:\jzhou\test_ping.ps1",ip] #args参数里的ip是对应调用powershell里的动态参数args[0],类似Python中的sys.argv[1]
p=subprocess.Popen(args, stdout=subprocess.PIPE)
dt=p.stdout.read()
return dt
except Exception,e:
print e
return False
if __name__=="__main__":
ip=["127.0.0.1"]
print python_call_powershell(ip)
如果报错,说禁止执行脚本,是因为没有权限,所以,把上面的一行代码换成
args=[r"C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe","-ExecutionPolicy","Unrestricted", r"D:\jzhou\test_ping.ps1",ip]
--结束END--
本文标题: python调用本地powershell
本文链接: https://www.lsjlt.com/news/189025.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0