Command Executor ignores error codes

Here you can submit bugreports
Post Reply
User avatar
kibi
Posts: 106
Joined: Mon Feb 29, 2016 12:57 pm
Contact:

Command Executor ignores error codes

Post 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
Alexander Sorkin
admin
Site Admin
Posts: 1659
Joined: Sat Feb 08, 2014 10:39 pm

Re: Command Executor ignores error codes

Post by admin »

Hi Alexander, thanx for reporting! I will take a look at it.

-steinar
emcodem
Posts: 1643
Joined: Wed Sep 19, 2018 8:11 am

Re: Command Executor ignores error codes

Post 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"
emcodem, wrapping since 2009 you got the rhyme?
admin
Site Admin
Posts: 1659
Joined: Sat Feb 08, 2014 10:39 pm

Re: Command Executor ignores error codes

Post 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
emcodem
Posts: 1643
Joined: Wed Sep 19, 2018 8:11 am

Re: Command Executor ignores error codes

Post 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):

Code: Select all

dir y:

Success (wrong behaviour)

Code: Select all

cmd /C "dir y:"

Failure (which is the correct behaviour)
emcodem, wrapping since 2009 you got the rhyme?
admin
Site Admin
Posts: 1659
Joined: Sat Feb 08, 2014 10:39 pm

Re: Command Executor ignores error codes

Post 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
emcodem
Posts: 1643
Joined: Wed Sep 19, 2018 8:11 am

Re: Command Executor ignores error codes

Post by emcodem »

Good to know, thanks steinar!
@kibi, can you confirm you can workaround by slowing down the batch?

cheers!
emcodem, wrapping since 2009 you got the rhyme?
User avatar
kibi
Posts: 106
Joined: Mon Feb 29, 2016 12:57 pm
Contact:

Re: Command Executor ignores error codes

Post by kibi »

Hi guys!

Here is my workflow + the batch file.
workflow.7z
(5.22 KiB) Downloaded 359 times
It's a bit messy, but there are some places in the batch where the process ends with commands:

Code: Select all

exit /B 2
exit /B 3
...
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.
Alexander Sorkin
emcodem
Posts: 1643
Joined: Wed Sep 19, 2018 8:11 am

Re: Command Executor ignores error codes

Post 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!
emcodem, wrapping since 2009 you got the rhyme?
Post Reply