how to run a waitbar in a batch script

조회 수: 3 (최근 30일)
Mikaël LE GRAND
Mikaël LE GRAND 2019년 4월 25일
댓글: Mikaël LE GRAND 2019년 4월 26일
I want to run a waitbar during execution of an excel macro running via activeX. First i wanted to test running a waitbar in a script ran by batch command.
Here is my code :
test.m
j = batch('test1');
test1.m
h = waitbar(0,'Patientez svp...');
fin = 10;
tic
while toc < fin
waitbar(toc/fin, h, 'Traitement Excel en cours...');
end
close(h)
When i run test.m, the waitbar never appears !
May someone could help me to understand what i'm doing wrong ?

채택된 답변

Edric Ellis
Edric Ellis 2019년 4월 26일
This is expected. The worker running your batch job has no access to your display, and cannot display any graphics (including a waitbar). In general, the only way to get status updates back to the client from a batch job is to have your task write "command-window" output - this can then be retrieved by calling the diary method of the job. For example:
% We deliberately capture the diary before the job is complete,
% so suppress this warning.
warning off parallel:batch:DiaryIncomplete
% Launch a batch script that prints out a message every 0.5 seconds
j = batch('slowOutput');
t = tic();
while ~wait(j, 'finished', 1)
diaryText = j.Tasks.Diary;
if isempty(diaryText)
fprintf('After %g seconds, diary still empty.\n', toc(t));
continue;
end
% Print out the last non-empty line of diary text
diaryLines = strsplit(strtrim(diaryText), newline);
fprintf('After %g seconds, last line of diary is: <%s>\n', ...
toc(t), diaryLines{end});
end
which on my machine prints out the following:
After 1.08259 seconds, diary still empty.
After 2.15081 seconds, diary still empty.
After 3.229 seconds, diary still empty.
After 4.30916 seconds, diary still empty.
After 5.39267 seconds, diary still empty.
After 6.48431 seconds, diary still empty.
After 7.58172 seconds, diary still empty.
After 8.6777 seconds, diary still empty.
After 9.77717 seconds, last line of diary is: <Completed iteration: 1>
After 10.886 seconds, last line of diary is: <Completed iteration: 3>
After 11.9932 seconds, last line of diary is: <Completed iteration: 5>
After 13.0959 seconds, last line of diary is: <Completed iteration: 7>
After 14.197 seconds, last line of diary is: <Completed iteration: 9>
and slowOutput.m is
for idx = 1:10
pause(0.5);
fprintf('Completed iteration: %d\n', idx);
end
  댓글 수: 1
Mikaël LE GRAND
Mikaël LE GRAND 2019년 4월 26일
Thanks a lot ! I understand now where i was wrong.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by