Running multiple Matlab commands in only one terminal from command prompt
36 views (last 30 days)
When we run a Matlab file from Windows command prompt, we generally use the following command line: (note the command is very simple, and it's just to illustrate the proceeding I am trying to develop)
matlab -nodesktop -r "a = 2"
Is there any way to, in another command through Windows command prompt, send a Matlab command (for example, fprintf('%d\n',a)) to the same terminal we've opened? Because if I type the following command:
matlab -nodesktop -r "fprintf('%d\n', a)"
it opens another terminal, just like the first one, and the variable a can't be read because there is no value associated to it !!
What I want to do is to send the fprintf command to the first Matlab terminal I've opened!
I hope my question is clear to everyone! =D
Thanks in advance!
Clayton Gotberg on 24 Apr 2021
On Linux I'm able to do exactly what you want with the -nodesktop -nosplash -nojvm options - it takes over the terminal window to let me send commands as if it's the MATLAB command line - but it doesn't seem possible on Windows.
When I executed your first statement, it opened a MATLAB command line window. If you're already entering something via command prompt, is there any reason you're not switching the window? If you know what code you'll be running in advance, why not write a script to execute with the run command?
Walter Roberson on 26 Apr 2021
MATLAB for Windows offers the Automation Server interface.
All MATLAB versions offer the Engine API so they can be called from other programs.
With Windows in particular, you may be able to use .NET System Diagnostic.Process to start MATLAB and connect other processes to input.
For Mac and Linux, you can create Named Pipes that look like files that you can read and write.