VBoxManage : Get error code in bash script
Posted: 14. Jul 2020, 23:27
Hello.
In a bash script this command return a normal error (because $L_VM_NAME2 is empty for the test) :
I can catch the batch error code with :
In normal situation without error, I need the value return by the command. So I store the result in a variable.
and got :
I need help to know if the command end with or without an error by testing 'L_RET_CODE2'.
Any comment is welcome.
In a bash script this command return a normal error (because $L_VM_NAME2 is empty for the test) :
Code: Select all
VBoxManage showvminfo "$L_VM_NAME2" | grep MAC | awk '{print $4}' | cut -d',' -f1
VBoxManage: error: Could not find a registered machine named ''
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2699 of file VBoxManageInfo.cpp
Code: Select all
VBoxManage showvminfo "$L_VM_NAME2" | grep MAC | awk '{print $4}' | cut -d',' -f1
L_RET_CODE1="${PIPESTATUS[0]}"
echo "L_RET_CODE1 : $L_RET_CODE1"
VBoxManage: error: Could not find a registered machine named ''
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2699 of file VBoxManageInfo.cpp
L_RET_CODE1 : 1Code: Select all
L_VM_MAC_ADDR_VALUE1=$(VBoxManage showvminfo "$L_VM_NAME2" | grep MAC | awk '{print $4}' | cut -d',' -f1)
L_RET_CODE2="${PIPESTATUS[0]}"
echo "L_RET_CODE2 : $L_RET_CODE2"
echo "L_VM_MAC_ADDR_VALUE1 : $L_VM_MAC_ADDR_VALUE1"
Code: Select all
VBoxManage: error: Could not find a registered machine named ''
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2699 of file VBoxManageInfo.cpp
L_RET_CODE2 : 0
L_VM_MAC_ADDR_VALUE1 :
Any comment is welcome.