我有一个看起来像这样的powershell脚本p1.ps1(不完全是,但这可以作为一个例子):
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Do the action."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Exit."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
Run Code Online (Sandbox Code Playgroud)
如何编写另一个脚本p2.ps1,它将运行第一个脚本(p1.ps1)并为其提供答案,以便p2.ps1执行时不会问任何问题?
我试过了:
echo y | p1.ps1
Run Code Online (Sandbox Code Playgroud)
但它没有做到这一点.