how can I send commands to 'command window' programly?
3 次查看(过去 30 天)
显示 更早的评论
Hello. I want to send "commands" to matlab command window programly
- I opened Matlab "Command window", in mac (Linux) type 'matlab -nodesktop' in terminal.
- I want to send matlab commends to matlab console (command window) in another terminal, or python script.
- because, i want to compare the results by matlab version 2010 and 2017, so i will open both version of matlab with no desktop, and run same script in each version using python. how could i do that?
0 个评论
采纳的回答
Walter Roberson
2019-2-9
matlab -nodesktop -r "try; NAME_OF_SCRIPT; catch; end; quit"
is probably the easiest to use, where NAME_OF_SCRIPT is a .m file that has already been created.
If you need to work with input that is not defined ahead of time, then create a named pipe and
matlab -nodesktop < NAMED_PIPE_FILENAME
and write to the named pipe in the place you are generating the input.
If your input generation is by way of a shell derived from the Bourne Shell, then you can use exec and numbered streams and & to start background jobs that you can write to selectively by using the correct output stream number redirection. You would go through that trouble if you were working with the two different MATLAB sessions simultaneously. If you were only working with one session at a time, then you would probably instead use |& to create a co-process and use print -p to send commands to it and read -p to read from it. Which is not to neglect the power of piping the output of a shell script into MATLAB:
./SHELL_SCRIPT_NAME | matlab -nodesktop
6 个评论
MrDan
2020-10-28
Walter, could you please extend your solution 1, i.e. launch Matlab with named pipe.
My bash code is this:
mkfifo my_pipe
matlab -nodesktop < my_pipe
echo "ls" > my_pipe
But Matlab won't receive my command.
Thanks!
Walter Roberson
2020-10-29
I just did a test with
cd /tmp
mkfifo /tmp/myfifo
/Applications/MATLAB_R2019a.app/bin/matlab -nojvm -nodesktop < /tmp/myfifo
then in a different shell window
echo ls >> /tmp/myfifo
The ls did get executed by MATLAB. Which then crashed. And there was no visible output until the crash.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!