LC Shell Script Outputs Only One Line to Terminal

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am

LC Shell Script Outputs Only One Line to Terminal

Post by icouto » 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:

Code: Select all

#! /applications/livecodeserver/livecode-server

put "Hello World!" & return & "Hello Galaxy!"
We get simply:
Hello Galaxy!Igors-iMac:~ igor$
Note that it does not even output a 'clearing' newline, and the prompt gets outputted directly after the result.
Trying the following has the same effect:

Code: Select all

#! /applications/livecodeserver/livecode-server

put "Hello World!" & return & "Hello Galaxy!" into it
put it
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:

Code: Select all

#! /applications/livecodeserver/livecode-server

put "Hello World!"
put return
put "Hello Galaxy!"
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:

Code: Select all

Hello World!
Hello Galaxy!

I saved it as 'test2.lc", and then I use Terminal to call the server and give the file as an argument for parsing:
Igors-iMac:~ igor$ /applications/livecodeserver/livecode-server ~/desktop/test2.lc
Hello World!
Hello Galaxy!
Igors-iMac:~ igor$
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.

This happens even if the server is forced to execute code halfway through parsing:

Code: Select all

Hello World! <?lc put return ?>Hello Galaxy!
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?

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am

Re: LC Shell Script Outputs Only One Line to Terminal

Post by icouto » Sun Apr 27, 2014 2:29 am

The problem described in the posting above is being experienced with LC Server 6.6.1.

I wonder whether this is a unicode-related problem - ie., a problem with the programatically-created return characters not being in the right encoding when sent to the Terminal.

The screenshot in this post seems to indicate that this should be possible:

http://livecode.com/blog/2014/03/06/livecode-server/

But I wonder whether this is a screenshot of scripts running under a LC Server 7.0 dp version. Scripts like that are certainly not working at my end with 6.6.1.

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am

Re: LC Shell Script Outputs Only One Line to Terminal

Post by icouto » Tue Apr 29, 2014 6:43 am

Ok, I found the source of the problem, so I'm posting it here for everyone else's benefit.

Apparently, different platforms (Win, Mac, Linux) use different characters for 'return' (line ending). Windows, in particular, uses "cr" or "crlf" while the other systems use "lf". LiveCode has a property, the outputLineEndings, which determines which character is used. For some reason, LiveCode Server, on the Mac, uses "cr" as a default - which is not recognised by the Mac's Terminal app as a return. The solution is to simply set the outputLineEndings to the correct return type - on the Mac, "lf":

Code: Select all

#! /applications/livecodeserver/livecode-server

set the outputLineEndings to "lf"
put "Hello World!" & return & "Hello Galaxy!"
Works as expected.

Post Reply

Return to “CGIs and the Server”