I think you could use a shell script command to eject a disk - drutil.
drutil tray eject
But I’m not sure if there is a way to trigger that from Handbrake.
So, flipping that around, if we’re already on the command line, perhaps you could script Handbrake to run from there using a shell script to control everything rather than Handbrake to trigger a subsequent action.
FWIW, both AppleScript and Automator are capable of triggering a shell script.