来自 az cli 命令的 powershell 重定向错误
powershell redirect error from az cli command
我是 运行 az CLI 命令 az mysql db show
。起初,数据库不存在,但这种情况在 try/catch 块中处理。打印错误信息:
ERROR: The requested resource of type 'Microsoft.DBforMySQL/servers/databases' with name 'my_name' was not found.
我不想打印此消息,因为我正在处理错误案例。我尝试了不同的方法来 redirect 错误输出流为空。我没能做到。我试过了:
command 2> $null # not working
和其他方法。
正确的语法是什么?
# from python in windows
az mysql db show 2>nul
# from powershell in windows - no space!
az mysql db show 2>$null
这应该更适合您。 Powershell 会吃掉你的 $null
,所以 azure cli 不会重定向。
您也可以尝试先使用 az mysql db list
检查数据库
我是 运行 az CLI 命令 az mysql db show
。起初,数据库不存在,但这种情况在 try/catch 块中处理。打印错误信息:
ERROR: The requested resource of type 'Microsoft.DBforMySQL/servers/databases' with name 'my_name' was not found.
我不想打印此消息,因为我正在处理错误案例。我尝试了不同的方法来 redirect 错误输出流为空。我没能做到。我试过了:
command 2> $null # not working
和其他方法。
正确的语法是什么?
# from python in windows
az mysql db show 2>nul
# from powershell in windows - no space!
az mysql db show 2>$null
这应该更适合您。 Powershell 会吃掉你的 $null
,所以 azure cli 不会重定向。
您也可以尝试先使用 az mysql db list