+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19

Thread: Environment Variables...HELP!

  1. #1

    Default Environment Variables...HELP!

    Anyone ever have any luck with 'putenv' / 'getenv' APIs? The putenv seems to work...I can check that the value was set with WRKENVVAR. The get ain't getting, though! The documentation says it returns a pointer to a string but no amount of contortions makes getenv work. Anyone ever use these? Have any ideas?

  2. #2
    Guest.Visitor Guest

    Default Environment Variables...HELP!

    The C header files map those APIs to some other functions. stdlib.h in QCLE has this code:
     #pragma map ( getenv, "Qp0zGetEnvNoCCSID") #pragma map ( putenv, "Qp0zPutEnvNoCCSID") 
    In RPG terms, this means
     D getenv PR extproc('Qp0zGetEnvNoCCSID') D putenv PR extproc('Qp0zPutEnvNoCCSID') 
    (I don't know why "getenv" doesn't work...) Barbara Morris

  3. #3
    Guest.Visitor Guest

    Default Environment Variables...HELP!

    Just a guess, but are you remembering to null terminate the name argument? That is: eval Arg = %trimr(EnvVarName) + Null and then passing the Pointer to Arg. Note that trailing blanks (prior to the Null terminator anyway) can be a differentiator when searching for names.

  4. #4

    Default Environment Variables...HELP!

    That did the trick! I had tried Qp0zGetEnv but not Qp0zGetEnvNoCCSID. Funny how just plain getenv doesn't work. Thanks much. I had just about given up hope. Tom

  5. #5

    Default Environment Variables...HELP!

    Good point. I hadn't added *NULL to the end of the strings. For simplicity my envvars where "one=1" and "two=2" and I had sized the strings used for put/get exactly. The Qp0zGetEnvNoCCSID worked...I may go back and try plain putenv/getenv with null term. strings just for kicks.

  6. #6
    Guest.Visitor Guest

    Default Environment Variables...HELP!

    To save handling the null terminators yourself, code the prototyped parameters and the calls like this:
     D getenv * extproc ('?') D parm * VALUE OPTIONS(*STRING) D env 32767a varying D p * C eval p = getenv ('PATH') C if p <> *NULL C eval env = %str (p) C endif 

  7. #7

    Default Environment Variables...HELP!

    Learn something new every day: C eval env = %str (p) I like that %str The real reason I'm checking into environment variables is I've been having trouble passing parms to a spawned program. I was advised to try using environment variables for this. The problem seems centered around the fact that spawn() passes parms C style int main(int argc, char *argv) which doesn't work out too well w/RPG. Then throw 'by reference/by value' into the mix. The spawn worked fine first time I tried it but now I want to get rid of the hard-coding and generalize it. Any ideas?

  8. #8
    Guest.Visitor Guest

    Default Environment Variables...HELP!

    Huh, learn something new every day! I didn't know that SPAWN passed parameters using the C convention. I don't think there's a way to get RPG to handle those parameters since they're passed by value. You could also use a data area or data queue to handle your parms. Barbara Morris

  9. #9
    G.Gaunt Guest

    Default Environment Variables...HELP!

    Tom, were you able to pass environment variables on the spawn parameter list?

  10. #10
    Guest.Visitor Guest

    Default Environment Variables...HELP!

    Tom or Barbara what service program do you have to bind to to use the APIs to get and set the ENVVAR. I looked in the docs and could not find an answer. This thread is a little old. Is it possible with V4R5 there is a QSYSINC member for the APIs?

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Using Environment Variables in RPG
    By jeffolen4 in forum General
    Replies: 5
    Last Post: 02-08-2006, 05:40 AM
  2. Indicator variables
    By buck.calabro@commsoft.net in forum SQL
    Replies: 4
    Last Post: 01-24-2005, 04:37 AM
  3. Variables and QMQRY
    By ukpi1b in forum General
    Replies: 0
    Last Post: 10-17-2004, 07:32 AM
  4. Variables in SQL statements?
    By Guest.Visitor in forum SQL
    Replies: 1
    Last Post: 01-27-2003, 06:35 AM
  5. Based variables
    By depalm@setarnet.aw in forum Programming
    Replies: 1
    Last Post: 08-25-2001, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts