There are many choices/design decisions to take at this point.
- The simplest idea is to publish the distance value as a latched topic. Then, in your second program, please make a subscriber, listening to the published topic. This way, you can easily get the distance value in your second program.
- Another approach could be making use of ROS Service. On the first program (node), please make a service server that returns the distance from the object. Then, please create a service client on the second program (node) to get the distance value.
Once you have the distance value, you can execute the move command.