Showing results for 
Show  only  | Search instead for 
Did you mean: 

This product reached the end of support date on March 31, 2021.

Recorder: Getting result from an executed batch cmd file

DynaMight Pro
DynaMight Pro

From a recorder script I want to run a batch (cmd) file. I am using Shell "<batchfile>".

I would like to record the result of the batch file, in particular the %errorlevel% that is returned, to determine the success and/or next step.

How can I accomplish this?




Hi Frans,

According to documentation, Shell function runs asynchronously,
and its return only reports on whether or not the new process has been spawned
successfully, but not on the results of the process execution. So, you will need to accomplish two things:

1.Waiting for the process to finish.

2.Checking the results once the process exits.

There could be different approaches to accomplishing this
task, some involve alternatives to Shell. The easiest, even though this is not an
elegant solution, you can just output errorlevel
in your cmd file, and then read the file once it exists, not locked, and not empty.

Note:There will be
very short periods when the file gets outputted when the former of these three
conditions is already true, but two others might be not yet true, so ideally you
should account for that. But,
considering that VBA is slow, by the time you come to the next line in your
code where you know that the file exists, output of the file will be finished,
even if you happen to check for existence when the file output was still in

Just in case, here are the links that you might take into

Hope you will come up with a solution that fits your needs
the best.

Thank you,


Hi Yuriy, thank you very much for the explanation, and usefull pointers.
I will investigate the information, and see if I can get it to work.