Skip to content

Running Commands

Exec opens an SSH session channel, requests remote execution, and collects standard output until the channel closes:

      r←c.Exec 'df -h /'
      r.rc
0
      ⎕←r.Data
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       196G   58G  128G  32% /

Any number of Exec calls can share one connection; each opens its own channel:

      {(c.Exec ⍵).Data} 'whoami'
alice

What Data contains

r.Data is the command's complete standard output.

  • Output that is valid UTF-8 is decoded to APL characters — including multi-byte text (é, →, CJK, …).
  • Output that is not valid UTF-8 (e.g. cat of a binary file) is returned as byte-preserving characters: one character per byte, values 0–255. Recover the raw bytes with ⎕UCS r.Data.

Commands themselves are sent UTF-8 encoded, so non-ASCII arguments and filenames work:

      r←c.Exec 'ls ''döcs'''

Large outputs are fine — the client reassembles output spanning many SSH packets and replenishes the flow-control window automatically.

Exit status, stderr, and signals

Beyond Data, the Exec result carries how the command ended:

Field Meaning
ExitStatus the command's exit code; ¯1 if the server sent none
Stderr the command's standard error (same UTF-8/binary rules as Data)
ExitSignal signal name (e.g. 'TERM') if the command was killed, else ''
      z←c.Exec 'ls /etc/passwd /nope'
      z.(ExitStatus Data Stderr)
2  /etc/passwd  ls: cannot access '/nope': No such file or directory

rc is about the SSH exchange, not the command

Exec 'false' returns rc 0 with ExitStatus 1: the exchange succeeded and the command reported failure. Check ExitStatus when the command's own success matters.

Failure modes

Result Meaning
rc ¯1, msg 'Not connected – call Connect first' no session — Connect first
rc ¯1, msg 'Exec request rejected' the server refused the exec request
rc ¯1, msg 'RecvPacket: read error …' the connection dropped or timed out mid-command (see WaitTime)