how to run a waitbar in a batch script
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mikaël LE GRAND
le 25 Avr 2019
Commenté : Mikaël LE GRAND
le 26 Avr 2019
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 ?
0 commentaires
Réponse acceptée
Edric Ellis
le 26 Avr 2019
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dialog Boxes dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!