Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

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

$ matlab -nodesktop -nojvm &

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

In other words, I want to have a matlab session running in the background, and execute matlab commands and/or scripts from an arbitrary terminal at any given time without having to create a new session.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"$'
'
  done
else
  tmux send-keys -t matlab "$@"$'
'
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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...