In PowerShell (5.1):
Calling an external command (in this case nssm.exe get logstash-service Application
) the output is displayed in PowerShell as I would have expected (ASCII-string "M:\logstash-7.1.1\bin\logstash.bat"):
PS C:\> M:\nssm-2.24\win64\nssm.exe get logstash-service Application
M:\logstash-7.1.1\bin\logstash.bat
But the following command (which pipes the output into Out-Default
) results in:
PS C:\> M:\nssm-2.24\win64\nssm.exe get logstash-service Application | Out-Default
M : \ l o g s t a s h - 7 . 1 . 1 \ b i n \ l o g s t a s h . b a t
(Please note all that "whitespace" separating all characters of the resulting output string)
Also the following attempt to capture the output (as an ASCII string) into variable $outCmd
results in :
PS C:\> $outCmd = M:\nssm-2.24\win64\nssm.exe get logstash-service Application
PS C:\> $outCmd
M : \ l o g s t a s h - 7 . 1 . 1 \ b i n \ l o g s t a s h . b a t
PS C:\>
Again, please note the separating whitespace between the characters.
Why is there a difference in the output between the first and the latter 2 commands?
Where are the "spaces" (or other kinds of whitespace chars) coming from in the output of the latter 2 commands?
What exactly needs to be done in order to capture the output of that external command as ASCII string "M:\logstash-7.1.1\bin\logstash.bat" (i.e. without the strange spaces in between)?
If the issue is related to ENCODING, please specify what exactly needs to be done/changed.