So how to send command to screen session from other terminal. In other words how to remote-control a screen session from within a script. This post is useful for this.
In particular, I wanted to execute matlab scripts in screen windows. To do this I used the following:
1. Create screen session
screen -S matlab2. Create few windows in the screen session using Ctr-a c
3. Send matlab command to each as follows
for ((i=0;i<$NO_WINDOWS;i+=1)); dowhere bashCalculations is my matlab script bashCalculations.m that takes part argument. So,, each screen window executes different part of my script.
screen -S matlab -p $i -X exec matlab -nodesktop -r "bashCalculations('part',$i+1)"