필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
tomy
tomy 2022년 9월 1일
댓글: tomy 2022년 9월 2일
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