LC Shell Script Outputs Only One Line to Terminal
Posted: Sat Apr 26, 2014 8:46 am
I have managed to setup Livecode Server successfully in my Mac, so I can use .lc files as shell scripts. I can put a shebang line at the top of the file, and it gets processed by the appropriate server binary. The problem is that I am getting unexpected output in the terminal, and I don't know whether I'm doing something stupid, or whether these are bugs. If someone could either enlighten me, or confirm, I'd appreciate it.
Problem: the server seems to be able to PARSE a file and directly output several lines of text to the Terminal, but if we try to create several lines of text and 'put' it to stdout, we only get the LAST LINE.
My first test script was this:
We get simply:
Trying the following has the same effect:
I thought maybe the server was sending each 'put' statement, one line at a time, to stdout, and perhaps because of buffering, only the last line was being returned, so I tried also:
But the result was the same - only the last line gets sent to the terminal.
I was a bit puzzled, because the server is basically a parsing engine, and it should therefore be capable of parsing and outputting several lines of text, which we should be able to see in the terminal. So I did another test: I created a simple, raw text file, containing just:
I saved it as 'test2.lc", and then I use Terminal to call the server and give the file as an argument for parsing:
This happens even if the server is forced to execute code halfway through parsing:
Produces the same error - only 'Hello Galaxy!' gets outputted.
Can someone point out what I'm doing wrong, or confirm that this is unexpected behaviour?
Problem: the server seems to be able to PARSE a file and directly output several lines of text to the Terminal, but if we try to create several lines of text and 'put' it to stdout, we only get the LAST LINE.
My first test script was this:
Code: Select all
#! /applications/livecodeserver/livecode-server
put "Hello World!" & return & "Hello Galaxy!"
Note that it does not even output a 'clearing' newline, and the prompt gets outputted directly after the result.Hello Galaxy!Igors-iMac:~ igor$
Trying the following has the same effect:
Code: Select all
#! /applications/livecodeserver/livecode-server
put "Hello World!" & return & "Hello Galaxy!" into it
put it
Code: Select all
#! /applications/livecodeserver/livecode-server
put "Hello World!"
put return
put "Hello Galaxy!"
I was a bit puzzled, because the server is basically a parsing engine, and it should therefore be capable of parsing and outputting several lines of text, which we should be able to see in the terminal. So I did another test: I created a simple, raw text file, containing just:
Code: Select all
Hello World!
Hello Galaxy!
As you can see, if the server *parses a file*, it outputs the file's text correctly split into proper lines, as they were in the file, directly to the terminal. No problem there. If we try to build text programatically, however, and send it to the Terminal via 'put', it seems to die.Igors-iMac:~ igor$ /applications/livecodeserver/livecode-server ~/desktop/test2.lc
Hello World!
Hello Galaxy!
Igors-iMac:~ igor$
This happens even if the server is forced to execute code halfway through parsing:
Code: Select all
Hello World! <?lc put return ?>Hello Galaxy!
Can someone point out what I'm doing wrong, or confirm that this is unexpected behaviour?