how can I send commands to 'command window' programly?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sungwon Min
am 8 Feb. 2019
Kommentiert: Walter Roberson
am 29 Okt. 2020
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 9 Feb. 2019
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 Kommentare
MrDan
am 28 Okt. 2020
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
am 29 Okt. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!