Check every two second if a EXE is running and do stuff

1 次查看(过去 30 天)
Hi,
i need to check every two seconds if a EXE (test.exe) is running. If YES then do nothing. If NO then check in a excel file a value... If value is Zero then start the test.exe.
Thank You all :)

采纳的回答

Chunru
Chunru 2022-9-2
编辑:Chunru 2022-9-2
Here is a skeleton you can based on:
% user a timer function
t = timer;
t.Period = 2;
t.TimerFcn = @check_exe;
start(t)
% timer callback function
function check_exe(mTimer,~)
% use tasklist to check process
[s, r] = system("tasklist");
% search the result r to see if the process is running
% perform tasks according to the checking status
end
  1 个评论
tomy
tomy 2022-9-2
Thank its working. I have just one Problem how to stop(t) in my case?
t=timer;
t.period=2;
t.TasksToExecute=inf;
t.ExecutionMode='fixedRate';
t.TimerFcn=@check_exe;
start(t)
function check_exe(mTimer,~)
%check if its already running
[~,b]=system('tasklist');
IsRunning_paint=contains(b,'Digitale_Ablegeschablone');
if IsRunning_paint(1)
fprintf('Digitale_Ablegeschablone ist bereits geöffnet!\n');
else
% filename='Parameter.xlsx';
% sheet=1;
% xlRange='B23:B24';
% Parameter=xlsread(filename,sheet,xlRange);
% Speicherstatus=Parameter(1);
% Blockstatus=Parameter(2);
load('Parameter.mat', 'Speicherstatus')
load('Parameter.mat', 'Block_beendet')
load('Parameter.mat', 'Save_Session')
if Save_Session==1
fprintf('Sitzung ist gespeichert. Digitale Ablegeschablone wird nicht geöffnet\n');
stop(t) %stop
elseif Block_beendet==1
fprintf('Sitzung ist beendet. Digitale Ablegeschablone wird nicht geöffnet\n');
stop(t) %stop
else
%start again (if its crashed)
system('C:\Users\christian\Desktop\TEST\EXE\Digitale_Ablegeschablone.exe &')
end
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Directed Graphs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by