Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
tomy
tomy am 1 Sep. 2022
Kommentiert: tomy am 2 Sep. 2022
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 :)

Akzeptierte Antwort

Chunru
Chunru am 2 Sep. 2022
Bearbeitet: Chunru am 2 Sep. 2022
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 Kommentar
tomy
tomy am 2 Sep. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by