Read from file - not working...

Are you using LiveCode to create server scripts or CGIs?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Read from file - not working...

Postby MartinB2 » Fri Aug 04, 2017 12:02 am

Having found the fix for getting "get Shell(xxx)" to work I have not got an other issue with V8.1.6 of the community server.

It appears that "read form file" does not work as expected.
As with the previous issue I have proven that my function works by running the stack in V8.16 community edition of the IDE. All works just fine.
But when I then run the function from a .lc file (I am using Apache running on Windows server 2012 R2 as the web server) the file contents does not appear to get fed into the it variable.
I check (by appending to a .txt trace file -- Oh so writing to a file works OK) the result of the file read and it is showing "eof" which is what I am expecting but the it variable appears to be empty.
As stated above using the IDE to run the same function that reads the same file it works exactly as expected.

This time I don't even get an error generated, unlike when I try and use revCopyFile - which generates a "handler not found" error < frustrating!

However I think I will be able to work around it by moving the function call to a stack that gets compiled as a .exe and run as a Windows service. Luckily it is not imperative that the function is triggered from the .lc page. it was just the most appropriate place to have it called from.

I will update this once I have proved the work around works, but I appreciate that this may not be a workaround that is suitable for anyone else that need to read a file.

Actually as I was typing the previous line I have thought of another work around that would work for me. I could put the file contents into a database as I have the .lc pages calling functions that read (and write) data from a MySQL server database.
Again maybe not an idea workaround for anyone else but just fine for me.

Regards - Martin
Posts: 6
Joined: Sat Apr 23, 2011 9:33 am

Re: Read from file - not working...

Postby Klaus » Fri Aug 04, 2017 10:54 am

Hi Martin,

if the files are not too big, use the URL syntax:
## For text:
put url("file:your_text_file.txt") into YourVariable
## For binary stuff
put url("binfile:your_binary_file.whatever") into YourVariable
that should work.


Posts: 9488
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: Read from file - not working...

Postby MartinB2 » Fri Aug 04, 2017 11:08 am

Hi Klaus,
you are right that should sort it out (the file I am trying to read is less than 200kb). I managed to get around the revCopyFile function not working by using put Binfile into another Binfile. It just didn't that the same approach would resolve this problem as well.

Thank you very much for your reply.

Best Regards - Martin
Posts: 6
Joined: Sat Apr 23, 2011 9:33 am

Return to CGIs and the Server

Who is online

Users browsing this forum: No registered users and 1 guest