python - PyCharm卡在subprocess.communicate上,脚本从CMD运行良好。 PATH在两者中都显示相同

标签 python powershell

我正在尝试将Powershell脚本作为Python中的子进程执行,并将输出通过管道传递回python。当我通过命令行运行此脚本时,它可以正常运行,但是现在我将其扔进了PyCharm中,它通过p.communicate挂起并挂起。

我已经从pycharm和CMD中打印出PATH进行比较,它们是一行一行的,没有看到很多其他答案,说明为什么这行不通。

码:

p = subprocess.Popen(r'powershell.exe powershell\DNfinder.ps1 group "{}"'.format(group),
                       stdout=subprocess.PIPE)

print('Opened first subprocess') #This statement prints every time

groupDN = p.communicate()

最佳答案

添加后在PyCharm中成功运行python脚本

stdin=subprocess.PIPE 


stderr=subprocess.PIPE

关于python - PyCharm卡在subprocess.communicate上,脚本从CMD运行良好。 PATH在两者中都显示相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43901669/

相关文章:

python - 如何在 WTForms 中使字段有条件地可选?

python randrange 重复选择

python - 在选项卡之间切换并关闭窗口中的选项卡会出错

xml - 在 PowerShell 中打印 XmlElement 名称

powershell - 如何列出IIS服务器中所有事件和唯一的ips连接

powershell - 将音乐复制到iPod

python - 如何在 Python 中将调用类名发送到记录器类 >

python - 通过 PyTumblr 仅返回 20 个帖子

powershell - 创建Powershell哈希表并导出到Excel

Powershell - 如何在一轮中获得扩展属性和法线?