1

I'm developing a wrapper around some LiveCode server-side scripts. Is there a way to exit a LiveCode script and specify an exit code? Right now, even unparseable code is given an exit code of 0. I'm looking for something like the exit to top control structure that will let me pass 0-255.

Here's a particularly painful example

$ cat test.lc
> #!/usr/bin/env livecode-community-server
  lakjreakl j3lkj4?KJ !$()U* @$)LFKDJ SKLmvnkl 32498*$#
  lkfj KJ# >J$? !*!$  kljflkjuia o1238

$ ./test.lc
> file "/home/ian/test.lc"
  row 2, col 11: Expression: bad factor (!)
  row 2, col 1: param: bad expression
  row 2, col 11: Commands: bad parameter (!)
  row 2, col 11: Commands: bad parameters (!)
  row 2, col 11: script: bad command (!)

$ echo $?
> 0
Ian Hunter
  • 9,466
  • 12
  • 61
  • 77

2 Answers2

2

You are looking for the quit command and its as yet undocumented exit code parameter which defaults to 0!

quit 1
Monte Goulding
  • 2,380
  • 1
  • 21
  • 25
  • Thank you. Just sent a support ticket to Livecode asking them to document this. This has been bothering me for quite some time. – Ian Hunter Mar 02 '16 at 17:04
  • Good work, it might also be worth seeing what they think about lc server exiting with a non-zero exit code if there was an execution error – Monte Goulding Mar 03 '16 at 02:40
1

You could try the "return" statement. It exits the current handler and whatever follows is sent to the calling handler. I haven't tried it on server but I'm thinking it might go to stdout if there is no calling handler: return "104"

"put" without a destination always goes to stdout, so you could alternately use "put 104" followed immediately by an "exit to top".

Jacque
  • 416
  • 2
  • 7