Is there any way to write to stdout or stderr in Dyalog 12.1 for Unix without using []NA? Alternatively, can you set the return value from the Dyalog process somehow to indicate success (retval 0) or failure?

We can do various workarounds (create a file with a return code and read that in a script surrounding the invocation of Dyalog) but to not be able to do it the direct way is kind of insane to be honest.

If we need to use []NA to write to stdout, can we make sure we do not trample on the fd's opened by Dyalog somehow? I know from experience that Dyalog can use fd's normally reserved for stdout/stderr for other things.

[Updated 2012-04-27 to add more detail about the exit codes][Updated 2015-08-12 to add details of exit codes 4-8][Updated 2016-06-21 to remove comment about codes 4-8][Updated 2017-07-17 to point out that RIDE libraries no longer exist in 16.0][Updated 2018-11-12 to add comment detail about codes 9-11]Hello Joakim

Since the very early days of Dyalog APL, we have split output across stdout and stderr.Anything assigned to ⎕ or returned to the session is written on stream 1 (stdout).Anything assigned to ⍞ or anything written by the session is written on stream 2 (stderr).

So for example the banner is written to stderr, and if you type

1+1

then the 1+1 is written to stderr, but the 2 is written to stdout.

[As as aside, from 12.1 onwards you can redirect the "status window" output elsewhere: set APLSTATUSFD to the stream that you want to use, and then when you start APL, redirect that stream to a suitable location. So

export APLSTATUSFD=9 mapl 9>status.out

will result in all the status window output being redirected to status.out]

Dyalog has a number of specific exit codes, but you can also follow ⎕off with an integer; this integer is used as the return code to APL. ⎕off is a niladic function; it is the parser which identifies this special "syntax". As a result of this, some expressions which you might expect to work won't.

We use this facility in the overnight QAs; I have standardised on 10 for success and 11 for failure of the QA code - then I can distinguish between a clean exit from Dyalog APL and a clean exit from my application (in this case, the QAs).

For completeness' sake I should also point out that you can use ⎕arbout, but you would need to be sure that you have opened the relevent stream before you start APL (by adding something like mapl 17>myfile) and only wrote to stream 17. Writing to other file descriptors, especially those associated with open files, is likely to have most undesirable consequences !

Messages intended for what would be the status window on a Windows platform are sent to file descriptor 2. Indeed even on a development platform they are displayed in your terminal but they are not part of the session so a screen redraw (Ctrl + L on most input translate tables) causes them to disappear.

In 14.1.25383 on onwards we have added two more exit codes which indicate problems with starting RIDE; I have also taken the opportunity to update the list to include all exit codes which the interpreter currently uses.

Note that we have also just fixed an issue which meant that APL terminated with an exit code of 0 even if a critical configuration paramenter was invalid.