Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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 :)

Risposta accettata

Chunru
Chunru il 2 Set 2022
Modificato: Chunru il 2 Set 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 Commento
tomy
tomy il 2 Set 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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by