Article
· Oct 5, 2023 1m read

How to get the return value of a routine or method in a Linux shell

InterSystems FAQ rubric

On Linux, use the iris command to execute a routine or method from a shell and get the return value.

For more information,  please refer to the document "About Instance Connections".

An example of a command is as follows.

iris terminal instname [arguments]

The return value of a shell script can be specified using a special variable using the Terminate() method of the %SYSTEM.Process class when the process ends, rather than by specifying an argument in the QUIT or RETURN command that is specified when a routine or method ends. Use the method of returning a value to $?.

The value can be between 0 and 255. An example of routine usage is as follows.

// Name the routine Test
start1() public {
 hang 5  // wait 5 seconds
 //The number specified in the second argument is the value returned to the shell
 set st=$system.Process.Terminate($JOB,11)
}

An example of execution is as follows.

# iris session iris -U USER "start1^Test()"
# echo $?
11

Examples of usage in class methods are as follows.

Class Test.Class1
{
ClassMethod test()
{
  hang 5 // Wait 5 seconds
  //The number specified in the second argument is the value returned to the shell
  set st=$system.Process.Terminate($JOB,12)
}
}

 

An example of execution is as follows.

# iris session iris -U USER "##class(Test.Class1).test()"
# echo $?
12
Discussion (2)0
Log in or sign up to continue

So testing shows the old way was better in this case.

Failure
iris session ${INST} -U %sys << EOF

w "stopping the mirror 1 is sucess: " zw ##class(SYS.Mirror).StopMirror("MIRROR")

h

EOF

%SYS>

%SYS>
stopping the mirror 1 is sucess: "0 "_$lb($lb(2050,,,,,,,,,$lb(,"%SYS",$lb("e^Shutdown+7^MIRRORMGR^2","e^zStopMirror+4^SYS.Mirror.1^1","e^^^0"))))/* ERROR #2050: Mirror configuration not loaded */

%SYS>
Sucess
$ iris session ${INST} -U %sys << EOF
>
> zw ##class(SYS.Mirror).StopMirror("MIRROR")                                  <
> h
> EOF


%SYS>

%SYS>
stopping the mirror 1 is sucess: 1

%SYS>

Same either way :(
iris session ${INST} -U %sys '##class(SYS.Mirror).StopMirror("MIRROR")' ;echo $?
0