Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / GETENV issue

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. GETENV issue
#12938
Posted by: mestrini 2009-05-25 01:29:53
CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var1","", "ENVIRONMENT" /*droping the var*/
SAY GETENV("var1")
I'm having issues with fetching values that do not exist in the "ENVIRONMENT" by recieving the error: Environemnt variable can't be fetched

Is there any way to query the existance of the variable?
Message2.
#12939
Posted by: PeterJ 2009-05-25 02:14:35
a catch novalue will do:

CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var2",99, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var1","", "ENVIRONMENT" /*droping the var*/
SAY "Var1="myenv("var1")
SAY "Var2="myenv("var2")
EXIT 

myenv:
PARSE ARG myvar
DO
  result=GETENV(myvar) 
  CATCH NOVALUE
  RETURN -1
END
RETURN result 
Message3.
#12941
Posted by: Jeff Glatt 2009-05-25 04:54:23
Pete is now the official "Reginald Answer Guy". I'm also thinking of having him handle complaints.
Message4.
#12943
Posted by: PeterJ 2009-05-25 06:02:50
@Jeff: early retirements are not accepted! Retirement age not before 65!
... and yes: I love Reginald! Oops, that a man's name, in that case I am fond of Reginald!
Message5.
#12944
Posted by: mestrini 2009-05-25 06:22:36
Thanks for the quick response.

A couple of minutes after posting i remembered the CATCH and tried it but could only catch novalues of local variables. I had non idea i needed to create a function and parse.

BTW, have you tested it? I pasted the code to RPC and still get the same error.
Message6.
#12945
Posted by: mestrini 2009-05-25 06:55:55 Last edited by: mestrini 2009-05-25 06:57:38 (Total edited 1 time)
CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var2",99, "ENVIRONMENT" /*defining the var*/
/*CALL VALUE "var1","", "ENVIRONMENT"*/ /*droping the var*/
SAY "Var1="myenv("var1")
SAY "Var2="myenv("var2")
SAY "Var3="myenv("var3")
EXIT 

myenv:
PARSE ARG myvar
DO
  result=GETENV(myvar) 
  CATCH NOVALUE
  RETURN -1
END
RETURN result
I've commented 3rd line and added a "SAY" to a var not initialised and it worked as expected.
I'm thinking there's a problem with defining an empty variable. Running with uncommented 3rd line i had to restart RPC in order to clear the ENVIRONMENT 'clipboard' as 'var1' could no longer be passed into the environment.
Message7.
#12947
Posted by: Jeff Glatt 2009-05-25 09:17:50
I badly fractured my ankle (surgery and all) while out running, and was not walking for several months. Now I walk with a limp, and have just started to try a little running. So I feel (and walk) like I'm 65.

You can't "drop" an environment variable like that. You're just setting it to an empty string, which is not the same thing. If you need to really drop it, you could FUNCDEF an OS function:
FUNCDEF("DropEnvironment", ",str,void", "kernel32", "SetEnvironmentVariableA")
dropenvironment("var2")
Usually when you set an env variable, it stays set until your program ends (at which time the OS "drops" it. That's why you're not seeing this until you restart RPC. You'd observe otherwise with RxLaunch.exe). It's for these reasons that most Windows programmers do not bother with environment variables, and instead use config files or registry settings.
Message8.
#12949
Posted by: PeterJ 2009-05-25 14:24:43
@Jeff: I am sorry to hear, but remain patient it might take up to a year, before you are fully recovered. Nordic walking may be a good alternative for the next time.

@mestrini: I see what you mean, emptying a variable has the same behaviour as not being defined, but does this really make a difference for the coding?
Message9.
#12961
Posted by: mestrini 2009-05-27 16:18:42
Sorry too to hear about your ankle (and you may think i'm joking) but i twisted mine a month ago playing football (european, not american, hehe) and it still aches and i also walk like i'm 65 (which i'm not). Hope you get better soon.

As for the environment variables i see that i'm not dropping them after all but instead 'blanking' them (which is better) but then how do i fecth an environment variable that is an empty string? That would server my purposes even better.

I understand that the env variables remain after script finishes while RPC is opened but i share values between scripts and it's a comfortable way to do it.


PS:
Off-topic
How's Linux Reginald going? Is it still going?
Message10.
#12964
Posted by: Jeff Glatt 2009-05-27 23:25:35
GETENV won't trigger NOVALUE even if the variable has an "empty" value. You'll just get an empty string.

Reginald Linux is on hold while I finish some other projects.
Message11.
#12965
Posted by: mestrini 2009-05-27 23:56:50
I believe i don't get an empty string; I get the behaviour mentioned in the opening post.
CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var1","", "ENVIRONMENT" /*emptying the var*/
SAY GETENV("var1")
This results in Environemnt variable can't be fetched

and even if i give the var a new value the error comes up
CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var1","2", "ENVIRONMENT" /*redefining the var*/
SAY GETENV("var1")
Once the var is emptyed the interpreter never recovers (except closing it)
Message12.
#12966
Posted by: PeterJ 2009-05-28 00:25:41
@Jeff: not quite right:

CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
DO
SAY GETENV("var1")
    CATCH NOVALUE
    SAY "var1 not defined or empty"
END
CALL VALUE "var1","", "ENVIRONMENT" /*defining the var*/
DO
SAY GETENV("var1")
    CATCH NOVALUE
    SAY "var1 not defined or empty"
END
DO
SAY GETENV("var2")
    CATCH NOVALUE
    SAY "var2 not defined or empty"
END

returns

1
var1 not defined or empty
var2 not defined or empty

which means novalue has been set, that an empty string also triggers a novalue might be overdone, but seems acceptable.

@mestrini: I can't confirm your described behaviour. If I add

CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var1","2", "ENVIRONMENT" /*redefining the var*/
SAY GETENV("var1")

I see the new "2" as result
Message13.
#12967
Posted by: mestrini 2009-05-28 04:48:06 Last edited by: mestrini 2009-05-28 05:36:50 (Total edited 2 times)
Strange. I get the error while running your script

I'm in Vista btw, and also running portable Reginald, i.e., i extracted the files and copied them to RPC folder, which is also portable.

Will install all and see if i get same errors.
Message14.
#12969
Posted by: mestrini 2009-05-28 05:58:44
Installed all, rebooted PC and still get same error.

Don't know what more to say...
Message15.
#12971
Posted by: PeterJ 2009-05-28 12:58:39
I am on XP and using the latest Reginald DDL. I tried it on different CPUs, all with the same result. Do you use Reginald lite, latest version?
Message16. Re:
#12973
Posted by: mestrini 2009-05-28 23:06:52
I am on XP and using the latest Reginald DDL. I tried it on different
CPUs, all with the same result. Do you use Reginald lite, latest version?

Yes, i downloaded latest versions to do a fresh install. Maybe it's a Vista issue.
Message17.
#12974
Posted by: PeterJ 2009-05-29 01:24:28 Last edited by: PeterJ 2009-05-29 01:31:58 (Total edited 2 times)
oh dear, I reproduced the problem on my son's Vista machine!

CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
CALL VALUE "var1","", "ENVIRONMENT" /*defining the var*/
DO
SAY GETENV("var1")
    CATCH NOVALUE
    SAY "var1 not defined or empty"
END

returns: var1 environment variable can't be fetched.
Conclusion might be to not reset the variable by passing a null string.

If the variable isn't define yet, as var2 in the following example, the
CATCH NOVALUE works fine.

CALL VALUE "var1",1, "ENVIRONMENT" /*defining the var*/
DO
SAY GETENV("var2")
    CATCH NOVALUE
    SAY "var1 not defined or empty"
END

My circumvention would be to never reset it, but mark it with a unique value as "not longer valid".
e.g.   

CALL VALUE "var1",-1, "ENVIRONMENT" /*defining the var*/

and to treat this situation with the following coding:

DO
varcont=GETENV("var2")
    CATCH NOVALUE
    SAY "var2 not defined or empty"
END
IF varcont=-1 THEN SAY "var2 not defined or empty"
Message18.
#12975
Posted by: mestrini 2009-05-29 04:09:04
Yep. That's what i usually do. I set the var to a value like "no file".
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥1,800.00 ·
 
 
¥489.00 ·
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥748.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0