Matlab standalone exe closes after calling another Matlab exe from it

2 views (last 30 days)
I am calling one exe from command propmt. It has one command line which calls another Matlab standalone application. These two applications need to communicate to each other via a .mat file. But, just after the first exe calls second exe, first exe is closing on it's own ( observed in Taskmanager). Even i have tried removing all clear statements from the seond exe. I am using memorymap for the ,mat file to share the data between the two applications. I do not understand the problem behind it. I don,t have parallel computing toolbox.
Calling of second exe from Matlab is running without any difficulty. Even i Have tried running the scripts in two different Matlab sessins which were running without any problem.
I am using ! Trial_memap_Mod1.exe & command to call second exe from the first.
Any suggestions would be of great help.
  2 Comments
Mario Malic
Mario Malic on 6 Mar 2021
This is very complex problem that you're having and without clear explanation I doubt that anyone can suggest something. Are you running the two instances of the same standalone executable MATLAB program? You can test if that's possible in general, by creating another different app and try it. Try launching your app normaliy by doubleclicking the app and when its launched, try to open it once again, and see what happens.
Manish
Manish on 8 Mar 2021
Edited: Manish on 8 Mar 2021
Thanks for the reply.
I am running two different standalone executables. The main standalone is calling the second executable whch establishes a udp connection and acquire data. This data is then written to the .mat file. After this process the first standalone has to read the data from .mat file for further processing and resets the flag so that second standalone can again acquire the data.
Launching the app by normally clicking is also closing the first executable after second executable is called from it. Please find the attached code.
First executable code is as below
clc
clear vars
echoudp('off')
z= timerfindall;
if ~isempty(z)
delete(z)
end
instrreset;
% some intializtions for variables and Memory sharing files
! Trial_memap_Mod1.exe & % calling second executable
a=timer('ExecutionMode','fixedRate','Period',1,'TimerFcn',@(~,~)readdata);
start(a)
function readdata(obj,event)
try
if m_table.Data.table_flag==0
Table=m_table.Data.data1
m_table.Data.table_flag=1;
end
if m1.Data.flag1==0
x= m1.Data.data;
m1.Data.flag1=1;
i=i+1;
end
if i>100
!taskkill -f -im Trial_memap_Mod1.exe % killing second executable
stop(a)
end
catch
delete(timerfindall)
end
end
Here m1, m_table are memory sharing files with variables flag1, data1, data, table_flag
second stanalone exceutable code is as follows
instrreset;
echoudp('off')
% intializations
try
while i<= 400
tic
if m.Data.flag1==0
pause(0.05)
continue
end
j=1;
Channels = zeros(8,1);
m_table.Data.table_flag=1;
% some data acquisition code lines here
% code for writing the data acquired after all ocnditions are met to .mat file as below
m.Data.Mod1_packet=double(Mod_packet);
m.Data.flag1=0;
m_table.Data.table_flag=0;
i = i+1
end
catch ME
echoudp('off')
error(ME.message)
end
here, m , m_table are variable for memory shared files. flag1, flag are used for status check of data writing and data reading.
I can able to run the scripts in two different sessions perfectly. I have tried running the second standalone from first script with success. But running second standalone from first standalone is causing closure of first standalone.

Sign in to comment.

Answers (1)

Mohammad Sami
Mohammad Sami on 8 Mar 2021
I would suggest, don't use timers in the first exe. Use while loop with some exit condition and a pause instead of timer.
% first exe.
% startup code.
% start 2nd exe
somecondition = true;
while somecondition
% read data from 2nd exe and do something
% do something
pause(1); % use 1 second pause instead of timer.
% terminate first exe by setting while loop condition to false
% somecondtion = false;
end

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!