Must "require" and "include" files be in the same directory

Are you using LiveCode to create server scripts or CGIs?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Must "require" and "include" files be in the same directory

Post by edgore » Wed Jan 23, 2013 12:45 am

I am just starting to use the Rev server and I am immediately running into behavior that I don't understand. I am assuming that it's me doing something wrong, but I cannot figure out what.

I an application I am writing, which accepts input from a web page using POST. That part all works fine. The problem is that I have two libraries thatI want to use in the processing of this data. From the docs it looks like I should use the following to do this:

require "../lib/idlookup_lib.lc"
require "../lib/idmapping_lib.lc"

Here is a little picture of the layout of my server, showing that the lib folder is located at the same lever as the application folder:

http Root Dir
|_Application Folder
|_Lib folder

However, I get the error message:
file "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/apps/submitlist.lc"
row 4, col 1: include: could not find file (idmapping_lib.lc)
file "..\lib\idlookup_lib.lc"

I also tried moving thing around, so that the lib folder is under the apps folder and using
require "/lib/idlookup_lib.lc"
require "/lib/idmapping_lib.lc"

This gets me the same error. Finally I stuck everything in one folder and used
require "idlookup_lib.lc"
require "idmapping_lib.lc"

Which works, but it's not the way I want to organize things on the server.

Am I doing something wrong here, or is livecode really only able to find an include/require if it's in the same directory as the script that calls it? Or is there some mystical starting location for the relative path that I should be using but don't know about?

Thanks for any possible assistance!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5147
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Must "require" and "include" files be in the same direct

Post by Mark » Wed Jan 23, 2013 12:53 am

Hi,

All your .lc files should be in the web sharing folder, just like usual .html and .php files. This also applies to libraries.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: Must "require" and "include" files be in the same direct

Post by edgore » Wed Jan 23, 2013 1:01 am

My picture did not come out right...

Both the apps and lib folders are under the http root folder

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: Must "require" and "include" files be in the same direct

Post by edgore » Wed Jan 23, 2013 7:52 pm

I also also tried using the complete path to the file I want to require, without any luck - for example:

require "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/lib/idlookup_lib.lc"

Frustrating, since I cannot figure out what I am doing wrong.

I even addded a line to put the defaultfolder in the script that is trying to require the libraries and it comes back with exactly what I expected, the defaultfolder is the folder thatn contains the executing script, so my relative paths *should* be working...

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: Must "require" and "include" files be in the same direct

Post by sturgis » Wed Jan 23, 2013 8:20 pm

You might do a shell call with a simple dir command to get a visual of what is "seen" at that location.

put shell("dir ../whateverpath/*")

Also a put shell("cd") should return the directory that shell starts in. (most likely the same as the defaultfolder but its worth a look to make sure nothing strange is going on)

the ../../whatever method is working for me but this is on osx. As mentioned by mark, if the files are outside the area allowed by apache (I forget the security settings that define where files can be placed and still accessible) then you'll have problems also. Might check the result after your include to see what the exact error message is (if you don't already)

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: Must "require" and "include" files be in the same direct

Post by edgore » Wed Jan 23, 2013 11:33 pm

Thanks for the suggestions!

There is definately something strange going on. Here is the output from the suggested shell commands (after swapping the slash direction):

output of put shell("cd")
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\idlookup <- this is the directory I expect, where the running script is located

output of put shell("dir ..\lib\*")
Volume in drive C is Local Disk Volume Serial Number is E2B8-A405 Directory of C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lib 01/22/2013 04:09 PM <- this is /lib, the directory I expect, where my libraries are.
. 01/22/2013 04:09 PM
.. 09/24/2012 08:42 AM 50 emailstring.txt
01/23/2013 12:57 PM 10,387 idlookup_lib.lc <-this is one of the libraries I am trying to require (see previous posts)10/04/2012 01:11 PM 92 idmapconfig.txt
01/22/2013 03:14 PM 4,009 idmapping_lib.lc <-this is the other library I am trying to require (see previous posts)
12/19/2012 08:18 PM 12,884 idmaps.txt
09/13/2012 08:22 AM 58 ldapstring.txt
09/26/2012 07:50 AM 0 libstring.txt
09/24/2012 08:47 AM 58 racfstring.txt
8 File(s) 27,538 bytes 2 Dir(s) 181,783,871,488 bytes free

And everything I am using is under the htdocs directory - the "webshared"/allowed area for Apache. HTML & text files in these areas are accessible through the browser no problem.

It would surprise me if nobody else had noticed that require and include were this broken on the Windows server engine though, so I still assume it must be something I am doing. Everything works just fine when everything is tossed into one directory (which is what I am doing for now, but it's messy and useless for the long-term.

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: Must "require" and "include" files be in the same direct

Post by edgore » Wed Jan 23, 2013 11:58 pm

Well, it appears that I figured it out (it was the flipping of the slashes in the shell commands that made me think of it) , and I think it's a bug, or at least a "feature that is not very good".

Apparently, on Windows require and include want back slashes, not forward slashes. Doesn't everything else that's executed by the engine (as opposed to shell commands) want forward slashes regardless of platform, to avoid porting issues down the line?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: Must "require" and "include" files be in the same direct

Post by sturgis » Thu Jan 24, 2013 12:16 am

Oh, yep. Everything handled by the engine can work with / but as you figured out (good catch) since the shell command is actually being executed by the OS, you have to stick with the OS default delimiter. Don't know why I didn't notice the slashes before.

If you're coding cross platform, in many cases the shell call will be different anyway, so you'd end up checking platform, then using whichever shell string applied. (even something like traceroute differs based on os (tracert vs traceroute) as well as switches (/ vs -)

Still is kinda a pain though if you're like me and have automatic fingers. I naturally type the / since (lately) i'm on osx and linux with very minor windows interaction.

Really glad you figured it out. That sort of thing can be very hard to spot.

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: Must "require" and "include" files be in the same direct

Post by edgore » Thu Jan 24, 2013 4:26 am

Unfortunately, the original probem was with the include and require commands in the server engine, not with she'll commands.I think they are supposed to use forward slashes like everything else - there in nothing in the docs about platform differences. I think I will bug report it and see what they say.

Post Reply

Return to “CGIs and the Server”