Page 1 of 1
Command Executor ignores error codes
Posted: Fri Jun 21, 2019 3:13 pm
by kibi
Hi, Steinar!
It seems that the Command Executor processor does not catch exit codes.
I made a workflow to run a batch file like that:
prepare-and-make-avs.bat %s_original_full% %s_avs_path%
If some problems are detected, the batch returns the error code 1,2,3 or 4. If everything OK, it returns 0.
There are two next processors in the workflow - for OK and Error branch handling. But it runs an OK branch in any case. The flag "omit exit code" is unchecked.
Reproduced with 0.9.4.0
Re: Command Executor ignores error codes
Posted: Fri Jun 21, 2019 4:40 pm
by admin
Hi Alexander, thanx for reporting! I will take a look at it.
-steinar
Re: Command Executor ignores error codes
Posted: Mon Jun 24, 2019 12:34 pm
by emcodem
Hey!
i believe this is a "timing issue"; in case the batch is too fast for the ffastrans code for the cmd_run node, it does not catch the exit code correctly...
@kibi, i guess you can workaround by slowing down execution, e.g. add a ping:
cmd /C "ping 127.0.0.1 && YOURBATCHFILE.bat"
Re: Command Executor ignores error codes
Posted: Mon Jun 24, 2019 4:56 pm
by admin
Why do you believe that is the case, emcodem? Windows will store information like the exit code for that PID's handle for...I guess until the PID is reused. So long after the process has closed you can actually ask for the exit code if you know the PID, which FFAStrans definately does.
Alexander, maybe you can share your script and workflow so that we can take a look?
-steinar
Re: Command Executor ignores error codes
Posted: Tue Jun 25, 2019 6:49 am
by emcodem
Hmmm yesterday i seemed to be able to reproduce and solve it this way only. In the code of the cmd_proc, it does not wait for the process to exit which i normally do when spawning childs processes.
Waiting for a special exit code just feels wrong for me and i am not sure if it works in all conditions, also it can lead to a forever hanging process in case
exactly the special exit code is returned from the child. I did not play with the code but i just was not sure if the current strategy works out in all cases and as i did not see any other condition that could fail in the code, i thought that this must be the cause for this error (now i am not so sure anymore)
Interestingly, today the problem occurs to me only when i omit "cmd /C" but instead enter the command directly...
What i do is try to reproduce it with a dir command to a drive that does not exist, e.g. "dir T:"
So today it is like this for me (y: drive does not exist, so the commad should error):
Success (wrong behaviour)
Failure (which is the correct behaviour)
Re: Command Executor ignores error codes
Posted: Tue Jun 25, 2019 4:07 pm
by admin
Gotta hand it to you, emcodem; it seems you have a valid point after all regarding the "too fast for the ffastrans code"! When I tried yesterday with a batch-script containing only "exit 1" it worked flawless but with your
"cmd /C "dir y:"" example it does not.
So now I have changed the code to wait until the process exits before I ask for the exit code. Thanks emcodem!
-steinar
Re: Command Executor ignores error codes
Posted: Thu Jun 27, 2019 8:31 am
by emcodem
Good to know, thanks steinar!
@kibi, can you confirm you can workaround by slowing down the batch?
cheers!
Re: Command Executor ignores error codes
Posted: Fri Jun 28, 2019 11:02 am
by kibi
Hi guys!
Here is my workflow + the batch file.
It's a bit messy, but there are some places in the batch where the process ends with commands:
I run the batch from Command Executor node by calling it directly, without
cmd /C ...
Steinar, could you please send the hot fixed version?
So now I have changed the code to wait until the process exits before I ask for the exit code. Thanks emcodem!
P.S. I use the key /B to exit the batch, not a CMD where the batch is running:
Quits the CMD.EXE program (command interpreter) or the current batch
script.
EXIT [/B] [exitCode]
/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE
exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.
Re: Command Executor ignores error codes
Posted: Tue Jul 02, 2019 7:29 am
by emcodem
Hey Kibi,
at this point it is not 100% clear if the bug we detected before is the one that you hit. Looking at your batch it might not be the case.
-) can you confirm that "ping 127.0.0.1 && yourbatch.bat" solves the problem for you?
-) is there a special reason why you don't use cmd /C (it is generally not recommended to omit that part)
cheers!