在运行neofetch(Windows终端)后,PowerShell立即关闭。

huangapple go评论109阅读模式
英文:

powershell closes immediatly after running neofetch (windows terminal)

问题

我使用scoop安装了neofetch,并将其添加到了powershell的settings.json文件中:

"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe neofetch -nologo",

在neofetch的最后一行打印完后,neofetch命令会使其立即关闭。

我尝试使用-noexit参数,但没有成功,希望我能让它启动并使用neofetch,因为我喜欢它的外观。

英文:

I installed neofetch using scoop, and have it in the settings.json for powershell:

"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe neofetch -nologo",

the neofetch makes it close immediately after printing the last line of the neofetch.

tried using -noexit to no avail, hopefully i can get it to just boot and use neofetch becuase i like the way it looks lol

答案1

得分: 2

Mathias 提供了关键的指针:

  • PowerShell CLI的自有参数 - 例如你的情况下的 -NoLogo,以及经常使用的 -ExecutionPolicy-NoProfile-NoExit - 必须放在要调用的任何命令或脚本文件之前,并且其后的传递参数。

  • -File-Command 之后的任何内容 - 或者在两者都不存在的情况下 - 第一个不是 CLI 参数的参数被视为要执行的脚本文件或命令,其后的所有参数都会被传递。

因此:

  • powershell.exe neofetch -nologo 等同于 powershell.exe -Command neofetch -nologo,将 -nologo 传递给 neofetch 而不是 PowerShell,这可能导致它立即失败并退出。

  • 要按预期工作,你需要将 -nologo 放在 neofetch 之前;然而,在你的情况下,-nologo 实际上是不必要的(使用 -Command-File 时,-nologo 是_隐含的_,除非 -File-NoExit 结合使用);为了演示使用 -NoExit正确语法

# -NoExit(以及任何其他 PowerShell CLI 参数)必须首先出现。
# 等同于:
#   powershell.exe -NoExit -Command neofetch
powershell.exe -NoExit neofetch

在你的 JSON 文件上下文中:

"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit neofetch",

<sup>[1] 请注意,这两个 PowerShell 版本的 CLI 有_不同的默认值_:powershell.exe,即 Windows PowerShell CLI,默认为 -Command,而 pwsh,即 PowerShell (Core) CLI,默认为 -File。有关何时使用 -File-Command 的详细信息,请参阅此答案。</sup>

英文:

<!-- language-all: sh -->

Mathias has
provided the crucial pointer:

  • The PowerShell CLI's own parameters - such as -NoLogo in your case, and often -ExecutionPolicy, -NoProfile and -NoExit - must be placed before any command or script file to invoke and its subsequent pass-through arguments.

  • Anything that follows -File or -Command - or in the absence of either - the first argument that isn't a CLI parameter<sup>[1]</sup> is considered the script file or command to execute, with all subsequent arguments getting passed through, whatever they are.

Therefore:

  • powershell.exe neofetch -nologo is the same as powershell.exe -Command neofetch -nologo and passes -nologo to neofetch instead of to PowerShell, which presumably causes it to fail and exit right away.

  • You would have to place -nologo before neofetch to work as intended; however, -nologo isn't actually necessary in your case (with -Command and -File, -nologo is implied, except if -File is combined with -NoExit); to demonstrate the correct syntax with -NoExit instead:

# -NoExit (as well as any other PowerShell CLI parameters) must come *first*.
# Same as: 
#   powershell.exe -NoExit -Command neofetch
powershell.exe -NoExit neofetch

In the context of your JSON file:

&quot;commandline&quot;: &quot;%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit neofetch&quot;,

<sup>[1] Note that the CLIs of the two PowerShell editions have different defaults: powershell.exe, the Windows PowerShell CLI,, defaults to -Command, whereas pwsh, the PowerShell (Core) CLI, defaults to -File. See this answer for when to use -File vs. -Command.</sup>

huangapple
  • 本文由 发表于 2023年8月8日 21:37:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76860100.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定