matlab command (from bash / command line) on an already running session

前端 未结 2 1726
抹茶落季
抹茶落季 2020-12-08 17:41
$ matlab -nodesktop -nojvm &

How would I execute matlab commands on the session that was just created?

In other words, I want to have a

2条回答
  •  执念已碎
    2020-12-08 18:19

    I would suggest a similar solution as carandraug did, only I prefer tmux as the multiplexer. It may be a bit tricky getting the commands passed in correctly so create a shell-script that handles the details.

    Let's say you've started matlab in a terminal like this:

    tmux new -s matlab "matlab -nodesktop -nojvm"
    

    Now a tmux session called matlab is running matlab with no gui.

    Create this shell-script:

    mx

    #!/bin/bash
    
    if [[ $# -eq 0 ]]; then
      while read; do
        tmux send-keys -t matlab "$REPLY"$'\n'
      done
    else
      tmux send-keys -t matlab "$@"$'\n'
    fi
    

    In a different terminal you can now run quoted matlab commands:

    mx "A = reshape(1:9, 3, 3)"
    

    Or even pass commands in through a pipe:

    for mat in A B C; do echo "$mat = reshape(1:9, 3, 3)"; done | mx
    

提交回复
热议问题