英文:
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
-NoLogoin your case, and often-ExecutionPolicy,-NoProfileand-NoExit- must be placed before any command or script file to invoke and its subsequent pass-through arguments. -
Anything that follows
-Fileor-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 -nologois the same aspowershell.exe -Command neofetch -nologoand passes-nologotoneofetchinstead of to PowerShell, which presumably causes it to fail and exit right away. -
You would have to place
-nologobeforeneofetchto work as intended; however,-nologoisn't actually necessary in your case (with-Commandand-File,-nologois implied, except if-Fileis combined with-NoExit); to demonstrate the correct syntax with-NoExitinstead:
# -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:
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit neofetch",
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论