Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

Redirections changes "get-alias" command return code in powershell

$
0
0

I want test if an alias exists with the following code :

if( (get-alias ls) ) {    echo "=> Alias ls already exists."} else {    echo "=> Alias ls does not exist."}

When run, it says :

CommandType     Name                                               Version    Source-----------     ----                                               -------    ------Alias           ls -> Get-ChildItem=> Alias ls already exits.

I tried to redirect the output of the command to $null :

if( (get-alias ls >$null) ) {    echo "=> Alias ls already exits."} else {    echo "=> Alias ls does not exist."}

I expected this output when run :

=> Alias ls already exists.

But the outcome of the code snippet somehow changed :

=> Alias ls does not exist.

If I redirect after the first set of parenthesis, I also get :

=> Alias ls does not exist.

Why does redirection interfere with the result?


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>