Page 1 of 1

livecode-server's "put" returns numToChar(13) on Mac

Posted: Sun Nov 23, 2014 4:08 pm
by [-hh]
Mac OS X (10.10.1)

When I run on MacOS X a LC-shebang *from Mac-Terminal* that contains a CR, I get only a single line output.
Is there a way to work around livecode-server's "put"? It should output similar to
echo -e "Hello\n LC-world"
by /bin/bash.

Also LC's shell returns numToChar(13) instead of CR.
The file (see below) is UTF8 and has unix LF, as preferred.
  • TextWrangler (if one runs the file over its "#!"-menu) converts the output tcorrectly o multiline UTF8.
  • get shell ("./testfile.lc")
    and also
    get shell("livecode-community-server" && sTestInputPath)
    both return a string with cr replaced by numTochar(13), needs to be converted.
It doesnt matter if the shellcommand is bash, csh, ksh or zsh. Here is my test-script.

Code: Select all

on mouseUp
  set defaultfolder to "/Users/admin/Desktop"
  put "/Users/admin/Applications/LiveCodeCommunityServer-6_7_1_rc_2-Mac/" & \
        "livecode-community-server" into myCmd
  -- set shellcommand to "/bin/csh" -- bash, csh, ksh, zsh
  get shell("./testShell.lc")
  put it && (cr is in it) into fld 1
  get shell(myCmd && "./testShell.lc")
  put cr&cr& it && (cr is in it) after fld 1
end mouseUp
The content of file "testShell.lc":

Code: Select all

#!/Users/admin/Applications/LiveCodeCommunityServer-6_7_1_rc_2-Mac/livecode-community-server

putt

on putt
  put "Hello" & cr & "LC-world"
end putt

Re: livecode-server's "put" returns numToChar(13) on Mac

Posted: Sun Nov 23, 2014 11:24 pm
by Peter Wood
From some reason, presumably historical, the "newline" in the Mac LiveCode Server defaults to the pre-OS X "cr". There is an outputLineEndings property that you can set:

Code: Select all

set the outputLineEndings to "lf"
Hope this helps.

Re: livecode-server's "put" returns numToChar(13) on Mac

Posted: Mon Nov 24, 2014 12:01 am
by [-hh]
Hello Peter.

Sadly this didn't help here, neither an include in my "mouseUp" handler above nor in the test file.
But it works in CGI mode (Apache), thanks for this hint -- and also indirectly the hint to "outputextencoding", it's easier to script a LC-cgi with that.

A replace doesn't feed off bread; I simply wondered about the lot of effort that is needed to prepare a server script, especially beacuse calling this by GUI is not noticeably slower.

I asked for the Terminal mode by "#!" or "<? ... ?>" because of using Richard's server testing scripts in the 'IDE contributors' subforum. I like these "benchmarking project" they started there very much, but I'm not a server specialist.

Perhaps you could chime in there and explain what's the reason for the "GUI-is-not-slower" effect I reported (may be my scripts are misleading?).

Thanks, Hermann

Re: livecode-server's "put" returns numToChar(13) on Mac

Posted: Mon Nov 24, 2014 10:35 am
by Peter Wood
I'm surprised that didn't work for you. I ran this little script:

Code: Select all

#!livecode                   

set the outputLineEndings to "lf"
put "Hello, HH!" & return
from the OS X Terminal App :

Code: Select all

Schulz:LiveCodeServer peter$ ./hh.lc
Hello, HH!
Perhaps you could try it on your machine.

Re: livecode-server's "put" returns numToChar(13) on Mac

Posted: Mon Nov 24, 2014 2:13 pm
by [-hh]
Peter, I asked for multiline output.
But it now works:
It doesnt work in a GUI script that calls the server, but it *does* work in the server script.
I tested this part yesterday by mistake with LF (without quotes) instead of "LF". Sorry.

Thanks again for helping.

My results with Richard's server-testing-suite (in "IDE contributors") remain still the same.
GUI 6.7.1. is at least as fast as shebang by shell or <? ... ?> or shebang directly in terminal mode by livecode-community-server 6.7.1

Perhaps you can improve, apart from current issue, my stack script there?

Re: livecode-server's "put" returns numToChar(13) on Mac

Posted: Mon Nov 24, 2014 2:23 pm
by Peter Wood
Have you tried using return rather than cr?

Re: livecode-server's "put" returns numToChar(13) on Mac

Posted: Mon Nov 24, 2014 2:36 pm
by [-hh]
Yes.
It now works, as I said, if in the *server* script (the utf8-file) the following line is there:

[*] set the outputLineEndings to "LF" # <-- other beginner readers: watch the quotes!

whenever I use in the rest for building the report variable one of the constants
CR or return or LF or all three mixed (that's fine for collecting script parts from several sources).

Your hint [*] does the trick.
(Tested with LC 6.7.1, the fastest LC version of all times).