How to suppress output and check whether or not a command is successful?
问题 I am trying to write a powershell script that tests if a MySQL login is successful by using $? to check if an error occurs. I also want to suppress all output - successful or not successful - from the command. These are the things I've tried: mysql -u root --password=mypass -e "show databases" If ( $? ) { echo "Hooray!" } Else { echo "Boo!" } This works correctly but doesn't suppress any output. mysql -u root --password=mypass -e "show databases" > $null Works correctly still but does not