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
Now if I run the same command in powershell ISE as Administrator It shows RemoteException error.
Note that the service is actually getting sopped even if the response shows error.
I get the same kind of error response with girlab-runner's other commands like register
or start
. Commands are working but shows error in response and only happens in ISE.
CodePudding user response:
The implication is that your gitlab-runner.exe
call sends its output to stderr, not stdout.
Unfortunately, the ISE inappropriately renders stderr output from external programs as PowerShell errors, which is what you saw;
a simple way to provoke the symptom is to run cmd /c 'echo to stderr >&2'
The workaround is:
.\gitlab-runner.exe 2>&1 | % ToString # % is short for ForEach-Object
2>&1
is a redirection that merges stderr output into the success output stream, PowerShell's stdout equivalent.Converting the resulting stream of lines to strings (with
% ToString
) is necessary, because PowerShell wraps stderr lines inSystem.Management.Automation.ErrorRecord
instances.
However, you can avoid the need for workarounds by migrating away from the obsolescent ISE:
The Windows PowerShell ISE is no longer actively developed and there are reasons not to use it (bottom section), notably not being able to run PowerShell (Core) 7 .
The actively developed, cross-platform and cross-edition editor that offers the best PowerShell development experience is Visual Studio Code with its PowerShell extension.