powershell redirect error from az cli command

Viewed 345

I'm running an az CLI command az mysql db show. At first, the DB doesn't exist, but that case is handled in a try/catch block. There is an error message printed:

ERROR: The requested resource of type 'Microsoft.DBforMySQL/servers/databases' with name 'my_name' was not found.

I would like to not print this message since I'm handling the error case. I tried different methods to redirect the error output stream to null. I didn't manage to do so. I tried:

command 2> $null # not working

and other approaches.

What is the correct syntax?

1 Answers
# from python in windows
az mysql db show 2>nul

# from powershell in windows - no space!
az mysql db show 2>$null

This should work better for you. Powershell will eat your $null, so azure cli won't redirect.

You can also try checking for the db first with az mysql db list

Related