如何解决按是,否,Enter键以继续执行Powershell脚本
我有一个名为install.ps1
的脚本,它调用了install.py
。
当我执行.\install.ps1
时,如果我要升级python,它会提示我Y/N
。然后install.ps1
调用install.py,它会提示更多选项,例如要在其中安装python的目录,如果要使用默认路径,请按ENTER
。
我想使此过程自动化,其中我的自动化将自动按Y或N,然后按Enter 5次。
我尝试了此操作,但仍然提示我按Y/N
。我该怎么办?
echo "N`n`n`n`n`n" | .\install.ps1
编辑:这是给出来自install.ps1的第一提示的代码的一部分。在下一个提示之后来自install.py。
$message = 'Do you want to upgrade Python?'
$question = 'press Y? (Entering "n" will use existing python)'
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))
$decision = $Host.UI.PromptForChoice($message,$question,$choices,0)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。