Hello,
Note that most of the commands are synchronous. The only one you listed that is not is 'run'. But there is a 'runSync' command you can use instead. That will make sure your program has finished running (reached exit point and halted) before the disconnect command is called.
Thanks
ki