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

前端 未结 2 1724
抹茶落季
抹茶落季 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:12

    A possibility is to start a screen session, then start matlab on it, and detach from it. Anytime you want to use it, just fire up a terminal and reattach that screen session.

    Basically start screen (just type screen at a terminal), and start your matlab session. Then detach from the session (Ctrl+A followed by pressing D) and you'll be back to your terminal. You can close the window no problem, any process that started on screen will keep on running. Whenever you want to get it again (it's called reattach the session), just use screen -r. Take a look at the man page for all the other options.

    Note that a screen session can have any number of windows and you can also have multiple screen session at the same time. Take a good luck at some tutorials online, it's an extremely useful tool, specially but not only, if you connect a lot to other systems that may have need to run long jobs.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题