How to know if a program inside a container is finished?

Hi I have a situation where I need a run a docker exec to launch an executable inside a running docker container. I need to wait till the executable is finished and then need to copy the output file back to host machine and stop the container. How can I achieve that? please suggest.

is it easier to use the common best practice to just have one process within a container?
I would go that way and mount everything needed into the container.
That also later allows you to scale and it already has your “is the container==process running” thingy solved for you.

let me explain more why I need this.
I am running a multi container task, which starts from one container and then connect to other containers. before starting from the master container I need to make sure other containers are up and running. Once everything is fine, I need to launch an executable form the master container but I dont know how to track when that task is finished. Is there any docker way of doing this?