[英]Why is PowerShell script pausing when prompted for input?
I successfully ran 3 commands in my PowerShell script shortcut but after running the last command it prompts the user for "y" or "N" and in my script I want to input "y" and press enter.我在我的 PowerShell 脚本快捷方式中成功运行了 3 个命令,但在运行最后一个命令后,它提示用户输入“y”或“N”,在我的脚本中我想输入“y”并按回车键。
After looking at other posts such as this I have tried to ECHO the keystroke but it only works prior to the last command Here you can see the 1st Echo Successfully and the 2nd is stuck because it is paused or something在查看了诸如此类的其他帖子后,我尝试对击键进行回声,但它仅在最后一个命令之前起作用在这里您可以看到第一个回声成功,第二个被卡住,因为它已暂停或其他原因
PowerShell Script PowerShell 脚本
ECHO 'y'
spicetify config current_theme Sleek
spicetify config color_scheme futura
spicetify apply
ECHO 'y'
To feed automated responses to external programs that request interactive input, pipe those responses to them, which they receive via their stdin stream.为了向请求交互式输入的外部程序提供自动响应, pipe这些响应是他们通过标准输入stream 接收的。
Note that, as of PowerShell 7.3.1, a trailing newline (CRLF on Windows, LF on Unix) is automatically and invariably appended to a string you output from PowerShell so that, on Windows, sending 'y'
in effect sends "y`r`n"
, and that newline is usually interpreted as submitting input to an interactive prompt.请注意,从 PowerShell 7.3.1 开始,尾随换行符(在 Windows 上为 CRLF,在 Unix 上为 LF)自动且始终附加到字符串 you output from PowerShell,以便在 8874414387`88 上发送
'y'
"y`r`n"
,并且该换行符通常被解释为将输入提交给交互式提示。
Therefore, for every one among your spicetify
calls that may / does prompt for a y/n
response, do the following, using your last command as the example:因此,对于您的
spicetify
调用中的每一个可能/确实提示输入y/n
响应的调用,请执行以下操作,使用您的最后一个命令作为示例:
'y' | spicetify apply
Note how string literal 'y'
by itself is enough to produce output - no need for echo
, which in PowerShell is an alias for the rarely needed Write-Output
cmdlet - see this answer for more information.请注意字符串文字
'y'
本身如何足以生成 output - 不需要echo
,它在 PowerShell 中是很少需要的Write-Output
cmdlet 的别名 - 请参阅此答案以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.