Properly exiting the command

In some cases the callback function is not called by exec. For example, running 'pytest' as a command didn't call the callback. So calling cb() on exit event fixes this.