How to return the status code of Cache process to OS shell script?

Straight-forward way to do it is well known and looks like this: 
------------------------------------------------------------ sample #1 --------

echo "Try to freeze Cache instance $instance"
rm -f $mydir/db_temp
csession $instance -U%SYS << EOF >/dev/null
zn "%SYS"
set rc=##Class(Backup.General).ExternalFreeze()
set fn="$mydir/db_temp"
o fn:("WNS"):1 if \$t u fn w rc c fn
h
EOF
read rc < db_temp
if [ "$rc" = "1" ]
then
 echo "...OK, system is frozen."
else
 echo "** Copy ABORTED: freeze rc = $rc"
 exit
fi

-----------------------------------------------------------------------------------

Documentation states that the same can be written in much more short and readable style (and it really works):

------------------------------------------------------------ sample #2 --------

echo "Try to freeze Cache instance $instance"
csession $instance -U%SYS "##Class(Backup.General).ExternalFreeze()"
rc=$?
if [ $rc -eq 5 ]
then
 echo "...OK, system is frozen."
else
 echo "** Copy ABORTED: freeze rc = $rc"
 exit
fi

----------------------------------------------------------------------------------

Backup.General class lacks of source for some reason, so I tried to reconstruct it methods' behavior:

---

Class User.InstARMTune Extends %RegisteredObject
{
  ClassMethod ret(= 1) As %Integer
  {  return n  ; or quit n }

}
---

calling it in the same manner:

csession cache -U%SYS "##class(User.InstARMTune).ret(2)"
rc=$?

with no success: it allways returns 0. What I am doing wrong?
 

  • + 2
  • 0
  • 743
  • 2
  • 2

Answers

Try:

Do $System.Process.Terminate(,exitCode)

See documentation for reference. On older versions I believe the equivalent is:

Do $zu(4,$job,exitCode)

But this shouldn't be used if the nicer method is available.

A bit more information: $System.Process.Terminate was added in 2015.1.0.

I haven't tried this myself, but maybe use the Terminate method of %SYSTEM.Process

Comments

  Do $System.Process.Terminate(,exitCode) // works, thank you. It's nice enough for me.

Thanks for prompt responses, Timothy and John!