简体   繁体   English

从 Pycharm IDE 运行 PowerShell 脚本(Mac OS)

[英]Run PowerShell script from Pycharm IDE (Mac OS)

So I want to run a PS script that I have in my Python code, I just found this article: https://data-geek.medium.com/running-powershell-script-with-python-53a908da7d34所以我想运行我的 Python 代码中的 PS 脚本,我刚刚找到这篇文章: https://data-geek.medium.com/running-powershell-script-with-python-53a908da7d34

Since I'm using MacOS, it I changed it:由于我使用的是 MacOS,因此我对其进行了更改:

import subprocess, sys

p = subprocess.Popen(["powershell.app",
              "/Users/myuser/Downloads/powershellscript.ps"],
              stdout=sys.stdout)
p.communicate()

I've got an error, I guess the problem is with powershell.app.我有一个错误,我想问题出在 powershell.app 上。

How can I execute this PS script from my Python code?如何从我的 Python 代码执行此 PS 脚本?

instead of using "powershell.app" you want to use "pwsh".而不是使用“powershell.app”,您想使用“pwsh”。 This is the command the starts up powershell这是启动 powershell 的命令

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

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