フィルターのクリア

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 Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by