我使用 scoop 安装了 neofetch,并将其放在 powershell 的 settings.json 中:
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe neofetch -nologo",
neofetch
在打印 neofetch 的最后一行后立即关闭。
尝试使用 -noexit 无济于事,希望我可以让它启动并使用 neofetch 因为我喜欢它的样子哈哈
最佳答案
Mathias有 提供了关键指针:
PowerShell CLI的自己参数 - 例如您的情况下的
-NoLogo
,通常还有-ExecutionPolicy
、-NoProfile
和-NoExit
- 必须放置在要调用的任何命令或脚本文件之前及其后续传递参数。-File
或-Command
后面的任何内容 - 或两者都不存在 - 第一个参数不是 CLI 参数[1] 被视为要执行的脚本文件或命令,所有后续参数都会传递,无论它们是什么。
因此:
powershell.exe neofetch -nologo
与powershell.exe -Command neofetch -nologo
相同,并将-nologo
传递给neofetch
而不是 PowerShell,这可能会导致它失败并立即退出。您必须将
-nologo
放在neofetch
之前才能按预期工作;但是,在您的情况下实际上并不需要-nologo
(使用-Command
和-File
、-nologo
隐含,除非-File
与-NoExit
组合使用);使用-NoExit
来演示正确的语法:
# -NoExit (as well as any other PowerShell CLI parameters) must come *first*.
# Same as:
# powershell.exe -NoExit -Command neofetch
powershell.exe -NoExit neofetch
在 JSON 文件的上下文中:
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit neofetch",
[1] 请注意,两个 PowerShell 版本的 CLI 具有不同的默认值:powershell.exe
Windows PowerShell CLI 默认为 -Command
,而 pwsh
,PowerShell(核心)CLI,默认为 -File
。请参阅this answer何时使用 -File
与 -Command
。
关于windows - 运行neofetch后powershell立即关闭(Windows终端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76860100/