How to issue and execute commands in the Command Window of another MATLAB instance
I would like to have two instances of MATLAB running on my computer with some interaction between the two instances.
I am running MATLAB (R2024a) Update 2 on a Windows 10 computer.
Specifically I would like to:
Open a first instance of MATLAB in the usual way from the Window desktop
From the first instance of MATLAB open a second instance of MATLAB (ideally without another user interface opening up)
From the first instance of MATLAB tell the second instance of MATLAB to run a .m file
Run some code on the first instance of MATLAB
From the first instance of MATLAB tell the second instance of MATLABt to run another .m file
From the first instance of MATLAB close the second instance of MATLAB e.g. run the quit command
I have seen in other posts that this could be done using either a com server or .Net. I looked into the com server approach, but will have difficulties with that, because in our corporate installation, it is difficult to obtain needed administrative privileges.I am therefore most interested in the .Net approach. Also, I do not have the Parallel Processing Toolbox, so I can not use approaches that use that.
Following from some other related postings, e.g. ( https://www.mathworks.com/matlabcentral/answers/586706-how-to-redirect-standard-input-and-standard-output-using-net-system-diagnostics-process?s_tid=prof_contriblnk) I tried doing running this Hello World example from the first instance of MATLAB
NET.addAssembly(‘System’)
matlabProcess = System.Diagnostics.Process()
matlabProcess.StartInfo.FileName = ‘matlab’
matlabProcess.StartInfo.Arguments = ‘-nosplash’
matlabProcess.StartInfo.UseShellExecute = false;
matlabProcess.StartInfo.RedirectStandardInput = true;
matlabProcess.StartInfo.RedirectStandardOutput = true;
matlabProcess.Start();
matlabProcess.StandardInput.WriteLine("disp(‘Hello from MATLAB’)")
This sucessfully opens the second MATLAB instance, but no commands (e.g. disp(‘Hello from MATLAB’) appear in the command window of the second instance.
I know that there are simpler ways to launch a second instance of MATLAB and have it run just one command, however I need to start some processes running on the second instance, use the results of these in the first instance, and then thave the second instance run some code to gracefully stop some processes and shut down.
I posted an earlier version of this inquiry as a comment to the related question https://www.mathworks.com/matlabcentral/answers/1435767-how-to-opening-1-instance-of-matlab-from-matlab-but-accessing-it-multiple-times, but am now posting it here as its own question, along with some specific code that I tried, so it will reach others that might not be following that older question.
Thanks for any suggestions you can provide.
Best Wishes,
JonI would like to have two instances of MATLAB running on my computer with some interaction between the two instances.
I am running MATLAB (R2024a) Update 2 on a Windows 10 computer.
Specifically I would like to:
Open a first instance of MATLAB in the usual way from the Window desktop
From the first instance of MATLAB open a second instance of MATLAB (ideally without another user interface opening up)
From the first instance of MATLAB tell the second instance of MATLAB to run a .m file
Run some code on the first instance of MATLAB
From the first instance of MATLAB tell the second instance of MATLABt to run another .m file
From the first instance of MATLAB close the second instance of MATLAB e.g. run the quit command
I have seen in other posts that this could be done using either a com server or .Net. I looked into the com server approach, but will have difficulties with that, because in our corporate installation, it is difficult to obtain needed administrative privileges.I am therefore most interested in the .Net approach. Also, I do not have the Parallel Processing Toolbox, so I can not use approaches that use that.
Following from some other related postings, e.g. ( https://www.mathworks.com/matlabcentral/answers/586706-how-to-redirect-standard-input-and-standard-output-using-net-system-diagnostics-process?s_tid=prof_contriblnk) I tried doing running this Hello World example from the first instance of MATLAB
NET.addAssembly(‘System’)
matlabProcess = System.Diagnostics.Process()
matlabProcess.StartInfo.FileName = ‘matlab’
matlabProcess.StartInfo.Arguments = ‘-nosplash’
matlabProcess.StartInfo.UseShellExecute = false;
matlabProcess.StartInfo.RedirectStandardInput = true;
matlabProcess.StartInfo.RedirectStandardOutput = true;
matlabProcess.Start();
matlabProcess.StandardInput.WriteLine("disp(‘Hello from MATLAB’)")
This sucessfully opens the second MATLAB instance, but no commands (e.g. disp(‘Hello from MATLAB’) appear in the command window of the second instance.
I know that there are simpler ways to launch a second instance of MATLAB and have it run just one command, however I need to start some processes running on the second instance, use the results of these in the first instance, and then thave the second instance run some code to gracefully stop some processes and shut down.
I posted an earlier version of this inquiry as a comment to the related question https://www.mathworks.com/matlabcentral/answers/1435767-how-to-opening-1-instance-of-matlab-from-matlab-but-accessing-it-multiple-times, but am now posting it here as its own question, along with some specific code that I tried, so it will reach others that might not be following that older question.
Thanks for any suggestions you can provide.
Best Wishes,
Jon I would like to have two instances of MATLAB running on my computer with some interaction between the two instances.
I am running MATLAB (R2024a) Update 2 on a Windows 10 computer.
Specifically I would like to:
Open a first instance of MATLAB in the usual way from the Window desktop
From the first instance of MATLAB open a second instance of MATLAB (ideally without another user interface opening up)
From the first instance of MATLAB tell the second instance of MATLAB to run a .m file
Run some code on the first instance of MATLAB
From the first instance of MATLAB tell the second instance of MATLABt to run another .m file
From the first instance of MATLAB close the second instance of MATLAB e.g. run the quit command
I have seen in other posts that this could be done using either a com server or .Net. I looked into the com server approach, but will have difficulties with that, because in our corporate installation, it is difficult to obtain needed administrative privileges.I am therefore most interested in the .Net approach. Also, I do not have the Parallel Processing Toolbox, so I can not use approaches that use that.
Following from some other related postings, e.g. ( https://www.mathworks.com/matlabcentral/answers/586706-how-to-redirect-standard-input-and-standard-output-using-net-system-diagnostics-process?s_tid=prof_contriblnk) I tried doing running this Hello World example from the first instance of MATLAB
NET.addAssembly(‘System’)
matlabProcess = System.Diagnostics.Process()
matlabProcess.StartInfo.FileName = ‘matlab’
matlabProcess.StartInfo.Arguments = ‘-nosplash’
matlabProcess.StartInfo.UseShellExecute = false;
matlabProcess.StartInfo.RedirectStandardInput = true;
matlabProcess.StartInfo.RedirectStandardOutput = true;
matlabProcess.Start();
matlabProcess.StandardInput.WriteLine("disp(‘Hello from MATLAB’)")
This sucessfully opens the second MATLAB instance, but no commands (e.g. disp(‘Hello from MATLAB’) appear in the command window of the second instance.
I know that there are simpler ways to launch a second instance of MATLAB and have it run just one command, however I need to start some processes running on the second instance, use the results of these in the first instance, and then thave the second instance run some code to gracefully stop some processes and shut down.
I posted an earlier version of this inquiry as a comment to the related question https://www.mathworks.com/matlabcentral/answers/1435767-how-to-opening-1-instance-of-matlab-from-matlab-but-accessing-it-multiple-times, but am now posting it here as its own question, along with some specific code that I tried, so it will reach others that might not be following that older question.
Thanks for any suggestions you can provide.
Best Wishes,
Jon multiple instances MATLAB Answers — New Questions