简体   繁体   English

为什么 PowerShell 脚本在提示输入时暂停?

[英]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" ,并且该换行符通常被解释为将输入提交给交互式提示。

    • While this can be convenient, there are situations in which it is problematic - see this answer .虽然这很方便,但在某些情况下会出现问题 - 请参阅此答案

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.

相关问题 当提升 powershell 脚本以管理员身份运行时,为什么 read-host 在提示用户之前接受键盘输入? - When elevating a powershell script to run as an admin, why does read-host accept keyboard input before the user is prompted? 提示时强制Powershell脚本继续 - Force Powershell script to continue when prompted 防止弹出窗口暂停Powershell脚本 - Prevent popup from pausing powershell script Powershell调用命令行应用程序并在出现提示时传递变量 - Powershell call command line application and pass variables when prompted 在 PowerShell 和命令提示符上选择内容时避免暂停任务 - Avoid pausing tasks when select something on PowerShell and Command Prompt Powershell输入验证失败或生成异常时结束脚本 - End script when Powershell input validation fails or generates exception 提示时如何将参数作为输入传递给powershell脚本? - How to pass a parameter as an input to powershell script when it prompts? 为什么在Orchestrator 2012中使用变量时Powershell脚本会失败? - Why does Powershell script fail when using variables in Orchestrator 2012? 为什么这个简单的Powershell脚本在需要时不会退出? - Why does this simple Powershell script not exit when needed? 使用 Powershell 脚本将命令输入到 Powershell - Use Powershell script to input commands into Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM