Neat trick to capture error output of an external command without redirecting to a file or stream 1

Discovered this while messing around on Linux, but concept works everywhere –

PS /home/vagrant> [scriptblock]::Create('stat -c "%a %n" /etc/ssh/ssh_host_rsa_key/*').InvokeReturnAsIs() PS /home/vagrant> $Error[0] /bin/stat: cannot stat '/etc/ssh/ssh_host_rsa_key/*': Not a directory 

Cool!

submitted by /u/fourierswager
[link] [comments]

Leave a Reply