3 ms·
First few lines of the link answers that question: cmd1; if ($?) { cmd2 } = cmd1 && cmd2 cmd1; if (-not $?) { cmd2 } = cmd1 || cmd2 Just your usual Powershel
by nizmow 7y ago
First few lines of the link answers that question:
cmd1; if ($?) { cmd2 } = cmd1 && cmd2
cmd1; if (-not $?) { cmd2 } = cmd1 || cmd2
Just your usual Powershell verboseness.
- tyingq 7y agoTheir logical operators page says it also supports -and and -or. I can't tell if "cmd1 -and cmd2" would have already worked. It sounds like unadorned "cmd1" didn't return the equivalent of $? before this PR.
- jodrellblank 7y agoNo it wouldn’t work, cmd1 would return the stdout output of cmd1 if you could do that at all, but it would really try to use -and cmd2 as parameters to cmd1.
- tyingq 7y agoInteresting. Switching back and forth from Powershell and bash must be hard. Also $? has the exact opposite meaning in a Unix shell. $? as zero indicates success.
- felixfbecker 7y agoThe problem is that many old utilities in Windows don't use the exit code to indicate failure. PowerShell cmdlets have exceptions that can be caught with `try`/`catch`, and there's `-ErrorAction Stop`, but there was no good solution for native commands.