【发布时间】:2020-02-06 21:17:07
【问题描述】:
我已经知道如何通过 python 打开 windows 命令提示符,但我想知道是否有办法在 windows 10 上打开 windows powershellx86 窗口并通过 python 3.7 运行命令?
【问题讨论】:
标签: python powershell
我已经知道如何通过 python 打开 windows 命令提示符,但我想知道是否有办法在 windows 10 上打开 windows powershellx86 窗口并通过 python 3.7 运行命令?
【问题讨论】:
标签: python powershell
你可以使用subprocess.run调用powershell.exe
import subprocess
subprocess.run('powershell.exe Get-Item *')
【讨论】:
如果您知道如何运行命令提示符 (CMD.EXE),那么您应该能够使用相同的方法来运行 PowerShell (PowerShell.EXE)。 PowerShell.EXE 默认位于 c:\windows\system32\windowspowershell\v1.0\。要使用命令运行 shell:
c:\windows\system32\windowspowershell\v1.0\PowerShell.exe -c {commands}
要启动 .ps1 脚本文件,请使用
c:\windows\system32\windowspowershell\v1.0\PowerShell.exe -f Path\Script.ps1
祝你好运。
【讨论】: