I am trying to stop GitlabRunner windows service using powershell. When I execute the command in elevated powershell prompt, I see the following expected response
现在,如果我以管理员身份在 powershell ISE 中运行相同的命令,它会显示 RemoteException 错误。
请注意,即使响应显示错误,服务实际上也会受到影响。
我得到了与 Girlab-runner 的其他命令相同的错误响应,例如register
or start
。命令正在运行,但在响应中显示错误,并且仅发生在 ISE 中。
这意味着你的gitlab-runner.exe
调用将其输出发送到stderr,不是标准输出。
很遗憾,伊势不恰当地将外部程序的 stderr 输出呈现为PowerShell 错误,这就是你所看到的;
引发该症状的一个简单方法是运行cmd /c 'echo to stderr >&2'
The 解决方法 is:
.\gitlab-runner.exe 2>&1 | % ToString # % is short for ForEach-Object
-
2>&1
is a 重定向 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Redirection将 stderr 输出合并到成功中输出流 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Output_Streams,PowerShell 的标准输出等效项。
-
将生成的行流转换为strings (with % ToString
) 是必要的,因为 PowerShell 将 stderr 行包装在System.Management.Automation.ErrorRecord https://docs.microsoft.com/en-US/dotnet/api/System.Management.Automation.ErrorRecord实例。
但是,您可以通过迁移过时的 ISE 来避免需要解决方法:
-
Windows PowerShell ISE 是不再积极开发 https://docs.microsoft.com/en-us/powershell/scripting/components/ise/introducing-the-windows-powershell-ise#support and 有理由不使用它 https://stackoverflow.com/a/57134096/45375(底部),特别是无法运行PowerShell(核心)7+ https://github.com/PowerShell/PowerShell/blob/master/README.md.
-
积极开发的、跨平台、跨版本的编辑器,提供最佳的 PowerShell 开发体验是视觉工作室代码 https://code.visualstudio.com/以其PowerShell 扩展 https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)