1. CGI and Environment Variables
- Posted by GeorgeWalters Jul 26, 2009
- 1740 views
Apparently getenv only works for a specific list of environmental vars. FOr example
query = getenv("QUERY_STRING") works but query = getenv("DB") does not work. None of my env vars work. Can someone confirm and explain?
George
2. Re: CGI and Environment Variables
- Posted by jeremy (admin) Jul 26, 2009
- 1808 views
Apparently getenv only works for a specific list of environmental vars. FOr example
query = getenv("QUERY_STRING")
works but
query = getenv("DB")
does not work. None of my env vars work. Can someone confirm and explain?
George,
Is DB set for the current context? For instance, if you are in one console and type export DB=hello and then in another console run your Euphoria program, it will not be set. The DB variable is only valid for that given console. This is true on Windows and Unix.
Further, on Windows, if you use the System Settings to set a new Environmental variable, that does not take effect in current sessions. You have to start new sessions for new env vars to take effect (if set by the control panel in Windows).
Jeremy
3. Re: CGI and Environment Variables
- Posted by jeremy (admin) Jul 26, 2009
- 1744 views
Oh, here is an example...
C:\Users\Jeremy>type env.ex include std/pretty.e pretty_print(1, getenv("HELLO"), {3}) C:\Users\Jeremy>eui env.ex -1 C:\Users\Jeremy>set HELLO=Hello, World! C:\Users\Jeremy>eui env.ex "Hello, World!" C:\Users\Jeremy>
I have been using the getenv for a while now w/o any issue. The current unit tests pass as well. Can you give us a better idea of how you are using it?
Jeremy
4. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 26, 2009
- 1747 views
Apparently getenv only works for a specific list of environmental vars. FOr example
query = getenv("QUERY_STRING")
works but
query = getenv("DB")
does not work. None of my env vars work. Can someone confirm and explain?
George,
Is DB set for the current context? For instance, if you are in one console and type export DB=hello and then in another console run your Euphoria program, it will not be set. The DB variable is only valid for that given console. This is true on Windows and Unix.
Further, on Windows, if you use the System Settings to set a new Environmental variable, that does not take effect in current sessions. You have to start new sessions for new env vars to take effect (if set by the control panel in Windows).
Jeremy
I think I understand what you're saying. These are environmental vars that are set in windows control panel>>system>>advanced>>environmental variables. I use them to for info needed by the running program. However my cgi script programs can't get to them apparently.
5. Re: CGI and Environment Variables
- Posted by jeremy (admin) Jul 26, 2009
- 1665 views
I think I understand what you're saying. These are environmental vars that are set in windows control panel>>system>>advanced>>environmental variables. I use them to for info needed by the running program. However my cgi script programs can't get to them apparently.
George,
If that is the case then Apache is launching the CGI in a sub-process, not a full shell. You are going to have to revert to using mod_env with Apache. On windows, when I develop, I use Abyss web server, just because it's a lot easier to setup. With it, there is a web control panel and it allows you to set environmental variables for the CGI processes. mod_env will do the same thing. I do not know how to use mod_env, I just know of it's existence and purpose, otherwise I would give you detailed info on how to set it up. Sorry.
Jeremy
6. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 26, 2009
- 1718 views
thanks for suggestins.
I have used "shroud - clear" to remove all includes from the program (the're already loaded in) and then put a trace(3) in the cgi program. I also took out all getenv and hard coded their values. I found then what the problem is by using the ctrace.out file it produced.
initODBC() dbId = openConnectionODBC(dbName,dbUser,dbPassword) if dbId < 1 then --dbId = message_box("Can't open DataBase " & dbName,"",0) abort(1) end if
I cannot get to the data mysql database using Matt's odbc.e It aborts after not being able to connect.
Here's the tail end of the ctrace.out:
machine.e:288 poke(mem+length(s), 0) Thanks to Aku machine.e:290 return mem cgilib/odbc.ew:1242 a_ptr = allocate_string( authentication ) machine.e:285 mem = allocate(length(s) + 1) machine.e:55 return x >= 1 machine.e:105 return machine_func(M_ALLOC, n) machine.e:286 if mem then machine.e:287 poke(mem, s) machine.e:288 poke(mem+length(s), 0) Thanks to Aku machine.e:290 return mem cgilib/odbc.ew:1244 ok = c_func( SQLConnect, { getHandleODBC(hconn), s_pt cgilib/odbc.ew:971 if id > length( handle_odbc ) or handle_odbc[id] = -1 cgilib/odbc.ew:975 return handle_odbc[id] cgilib/odbc.ew:1248 free( h_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1249 free( s_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1250 free( u_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1251 free( a_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1253 if not SQL_SUCCEEDED( ok ) then cgilib/odbc.ew:924 return (rc = 0) or (rc = 1) cgilib/odbc.ew:1255 return -hconn cgilib/dbfile.e:187 if dbId < 1 then cgilib/dbfile.e:189 abort(1)
THE END
Does anyone know what to do about this? The programs runs without a problem when run from Crimson but when launched from ID it cannot connect to the data base. If I can't solve this my CGI days are over. Hopefully some bright sole knows the answer.
7. Re: CGI and Environment Variables
- Posted by jeremy (admin) Jul 26, 2009
- 1706 views
- Last edited Jul 27, 2009
thanks for suggestins.
I have used "shroud - clear" to remove all includes from the program (the're already loaded in) and then put a trace(3) in the cgi program. I also took out all getenv and hard coded their values. I found then what the problem is by using the ctrace.out file it produced.
initODBC() dbId = openConnectionODBC(dbName,dbUser,dbPassword) if dbId < 1 then --dbId = message_box("Can't open DataBase " & dbName,"",0) abort(1) end if
I cannot get to the data mysql database using Matt's odbc.e It aborts after not being able to connect.
Here's the tail end of the ctrace.out:
machine.e:288 poke(mem+length(s), 0) -- Thanks to Aku machine.e:290 return mem cgilib/odbc.ew:1242 a_ptr = allocate_string( authentication ) machine.e:285 mem = allocate(length(s) + 1) machine.e:55 return x >= 1 machine.e:105 return machine_func(M_ALLOC, n) machine.e:286 if mem then machine.e:287 poke(mem, s) machine.e:288 poke(mem+length(s), 0) -- Thanks to Aku machine.e:290 return mem cgilib/odbc.ew:1244 ok = c_func( SQLConnect, { getHandleODBC(hconn), s_pt cgilib/odbc.ew:971 if id > length( handle_odbc ) or handle_odbc[id] = -1 cgilib/odbc.ew:975 return handle_odbc[id] cgilib/odbc.ew:1248 free( h_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1249 free( s_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1250 free( u_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1251 free( a_ptr ) machine.e:60 return a > 0 and a <= MAX_ADDR and floor(a) = a machine.e:110 machine_proc(M_FREE, a) machine.e:111 end procedure cgilib/odbc.ew:1253 if not SQL_SUCCEEDED( ok ) then cgilib/odbc.ew:924 return (rc = 0) or (rc = 1) cgilib/odbc.ew:1255 return -hconn cgilib/dbfile.e:187 if dbId < 1 then cgilib/dbfile.e:189 abort(1)
THE END
Does anyone know what to do about this? The programs runs without a problem when run from Crimson but when launched from ID it cannot connect to the data base. If I can't solve this my CGI days are over. Hopefully some bright sole knows the answer.
Just formatted it a bit.
Jeremy
8. Re: CGI and Environment Variables
- Posted by mattlewis (admin) Jul 27, 2009
- 1718 views
cgilib/odbc.ew:1253 if not SQL_SUCCEEDED( ok ) then cgilib/odbc.ew:924 return (rc = 0) or (rc = 1) cgilib/odbc.ew:1255 return -hconn cgilib/dbfile.e:187 if dbId < 1 then cgilib/dbfile.e:189 abort(1)
Does anyone know what to do about this? The programs runs without a problem when run from Crimson but when launched from ID it cannot connect to the data base. If I can't solve this my CGI days are over. Hopefully some bright sole knows the answer.
It's hard to say. It might be easier if we knew what the error was. Take a look at getErrorODBC() or odbcError().
Matt
9. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 27, 2009
- 1691 views
cgilib/odbc.ew:1253 if not SQL_SUCCEEDED( ok ) then cgilib/odbc.ew:924 return (rc = 0) or (rc = 1) cgilib/odbc.ew:1255 return -hconn cgilib/dbfile.e:187 if dbId < 1 then cgilib/dbfile.e:189 abort(1)
Does anyone know what to do about this? The programs runs without a problem when run from Crimson but when launched from ID it cannot connect to the data base. If I can't solve this my CGI days are over. Hopefully some bright sole knows the answer.
It's hard to say. It might be easier if we knew what the error was. Take a look at getErrorODBC() or odbcError().
Matt
Sorry Matt, just got back from the weekend. Here's what I did
if dbId < 1 then fn = open("crash.txt", "w") if atom(dbId) then printf(fn,"%6d", dbId) elsif sequence(dbId) then printf(fn,"6s", dbId) end if
dbId = message_box("Can't open DataBase " & dbName,"",0) abort(1) end if the return code dbId = -2, hope that helps.
George
10. Re: CGI and Environment Variables
- Posted by mattlewis (admin) Jul 27, 2009
- 1703 views
cgilib/odbc.ew:1253 if not SQL_SUCCEEDED( ok ) then cgilib/odbc.ew:924 return (rc = 0) or (rc = 1) cgilib/odbc.ew:1255 return -hconn cgilib/dbfile.e:187 if dbId < 1 then cgilib/dbfile.e:189 abort(1)
Does anyone know what to do about this? The programs runs without a problem when run from Crimson but when launched from ID it cannot connect to the data base. If I can't solve this my CGI days are over. Hopefully some bright sole knows the answer.
It's hard to say. It might be easier if we knew what the error was. Take a look at getErrorODBC() or odbcError().
Matt
Sorry Matt, just got back from the weekend. Here's what I did
if dbId < 1 then fn = open("crash.txt", "w") if atom(dbId) then printf(fn,"%6d", dbId) elsif sequence(dbId) then printf(fn,"6s", dbId) end if --dbId = message_box("Can't open DataBase " & dbName,"",0) abort(1) end if
the return code dbId = -2, hope that helps.
No, George, that's not helpful at all. Please refer to my previous message.
Matt
11. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 27, 2009
- 1694 views
- Last edited Jul 28, 2009
No, George, that's not helpful at all. Please refer to my previous message.
Matt
[/quote]
Here's what I did.
if dbId < 1 then tmp = getErrorODBC(dbId) fn = open("crash.txt", "w") printf(fn,"%d %s", tmp) --dbId = message_box("Can't open DataBase " & dbName,"",0) abort(1) end if
Here's the message returned. Doesn't make sense to me. Running the program directly works but launching it from an html doc does not work.
0 IM002 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
12. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 27, 2009
- 1709 views
- Last edited Jul 28, 2009
No, George, that's not helpful at all. Please refer to my previous message.
Matt
Here's what I did.
if dbId < 1 then tmp = getErrorODBC(dbId) fn = open("crash.txt", "w") printf(fn,"%d %s", tmp) --dbId = message_box("Can't open DataBase " & dbName,"",0) abort(1) end if
Here's the message returned. Doesn't make sense to me. Running the program directly works but launching it from an html doc does not work.
0 IM002 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [/quote]
I found some references to this message using apache which I do not completely understand. I'm running an EU program that is a launched html doc from apache. I'm running apache 2.2.11 on Windows XP 2nd. Apparently I have to do some more work on apache, which I do not understand. Hopefully someone can take a look and explain to me what it's trying to say.
http://www.apachelounge.com/viewtopic.php?t=2545
Thanks. George
13. Re: CGI and Environment Variables
- Posted by gbonvehi Jul 28, 2009
- 1746 views
Hi George,
I didn't use ODBC as to tell you exactly if this will solve your problem, but I found the following post interesting in the forum thread you posted:
"Did you set up your "apache" ODBC datasource as a System DSN, so that Apache can find it?
A User DSN or File DSN is only available to you when you use an interactive program.
A System DSN is available to other processes - like Apache running as a Windows service."
And well, a quick search about how to do this: http://www.stylusstudio.com/docs/v2007/d_rdb20.html or http://www.webwizguide.com/kb/ASP_tutorials/setting_up_dsn.asp
Hope this helps,
Guillermo
14. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 28, 2009
- 1718 views
Hi George,
I didn't use ODBC as to tell you exactly if this will solve your problem, but I found the following post interesting in the forum thread you posted:
"Did you set up your "apache" ODBC datasource as a System DSN, so that Apache can find it?
A User DSN or File DSN is only available to you when you use an interactive program.
A System DSN is available to other processes - like Apache running as a Windows service."
And well, a quick search about how to do this: http://www.stylusstudio.com/docs/v2007/d_rdb20.html or http://www.webwizguide.com/kb/ASP_tutorials/setting_up_dsn.asp
Hope this helps,
Guillermo
Well, Thank You. It did help and happened to solve the problem. I also read that and had previously set up the DSN as a system DSN, tested it on the setup panel but stupid me did not click the OK button. Your message made me check it again and it was not there so I set it up again, tested, and made sure I clicked the OK button. Then launching an EU program from a html document worked. So Thanks for reminding me.
SO I have learned 2 important things from this 2 weeks of agony.
1. I have learned a lot from comments from those who know far more than I do and I am thankful for their help.
2. You cannot use getenv to retrieve your 'user environmental vars' that worked outside of apache and CGI programs. You must hard code them or setup them up in a txt file in the CGI directory. I suspect now looking at start >> control panel >> system >> advanced >> environmental panel where there are 2 sections, 'user environmental vars' and 'system environmental vars', that if I set the vars up under 'system environmental vars' they may be accessable from CGI programs. I'll check this and make a later post.
2. 'User DSN' setup does not work to access a database, you need to set up a 'System DSN'. I don't understand this but it solves the problem.
15. Re: CGI and Environment Variables
- Posted by GeorgeWalters Jul 28, 2009
- 1694 views
I suspect now looking at start >> control panel >> system >> advanced >> environmental panel where there are 2 sections, 'user environmental vars' and 'system environmental vars', that if I set the vars up under 'system environmental vars' they may be accessable from CGI programs. I'll check this and make a later post.
[/quote]
I checked this and environmental vars both user nor system can be obtained using getenv from a CGI program. I don't know why, just that id did not work for me.