Page 1 of 1

Setting Return Code at the end of a programm

Posted: Fri May 27, 2016 3:36 am
by p-OS
It seems it is currently not possible top set the (shell) return code of a compiled program when it quits.

If your program is meant to be called from a Shell with some self defined parameters, then it would be useful to set return code if it couldn't act as exspected, e.g. if it is called within a Shell script / Batch file...

One could define a new env variable and after program execution check the value of this env variable. But it would be more clean to use an OS' default mechanism.

I tried to set my OS' default result variable:

MorphOS:

Code: Select all

SetEnv("RC",30)
End
Besides the fact that the variable name has to be different depending on the OS running, it didn't work at all.
When a compiled Hollywood program exits, it always overrides the return code with value 0.

Imagine, your program gets an argument -textfile and shall do some operations on this file, this file might not be available -> thus porgram should quit with an error code

Code: Select all

If myaction_result="success"
  End  ; or End(0)
Else
  End(30)
EndIf

Re: Setting Return Code at the end of a programm

Posted: Sat May 28, 2016 5:22 pm
by airsoftsoftwair
Yes, this sounds like a useful extension. I'll try to implement this in a future version.

Re: Setting Return Code at the end of a programm

Posted: Tue Sep 20, 2016 9:38 pm
by airsoftsoftwair

Code: Select all

- New: End() accepts an optional argument now which allows you to set the program's exit status

Re: Setting Return Code at the end of a programm

Posted: Tue Sep 20, 2016 10:30 pm
by p-OS

Code: Select all

Print("Well done , Andreas :-D")
End(0)  -- default value...nonetheless ;)