|
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 |
1. GETENV issue #12938 |
CALL VALUE "var1",1, "ENVIRONMENT"
CALL VALUE "var1","", "ENVIRONMENT"
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? |
2. #12939 Posted by: PeterJ 2009-05-25 02:14:35 |
a catch novalue will do:
CALL VALUE "var1",1, "ENVIRONMENT"
CALL VALUE "var2",99, "ENVIRONMENT"
CALL VALUE "var1","", "ENVIRONMENT"
SAY "Var1="myenv("var1")
SAY "Var2="myenv("var2")
EXIT
myenv:
PARSE ARG myvar
DO
result=GETENV(myvar)
CATCH NOVALUE
RETURN -1
END
RETURN result
|
3. #12941 |
Pete is now the official "Reginald Answer Guy". I'm also thinking of having him handle complaints. |
4. #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! |
5. #12944 |
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. |
6. #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"
CALL VALUE "var2",99, "ENVIRONMENT"
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. |
7. #12947 |
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. |
8. #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? |
9. #12961 |
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? |
10. #12964 |
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. |
11. #12965 |
I believe i don't get an empty string; I get the behaviour mentioned in the opening post.CALL VALUE "var1",1, "ENVIRONMENT"
CALL VALUE "var1","", "ENVIRONMENT"
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"
CALL VALUE "var1","2", "ENVIRONMENT"
SAY GETENV("var1") Once the var is emptyed the interpreter never recovers (except closing it) |
12. #12966 Posted by: PeterJ 2009-05-28 00:25:41 |
@Jeff: not quite right:
CALL VALUE "var1",1, "ENVIRONMENT"
DO
SAY GETENV("var1")
CATCH NOVALUE
SAY "var1 not defined or empty"
END
CALL VALUE "var1","", "ENVIRONMENT"
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"
CALL VALUE "var1","2", "ENVIRONMENT"
SAY GETENV("var1")
I see the new "2" as result |
13. #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. |
14. #12969 |
Installed all, rebooted PC and still get same error.
Don't know what more to say... |
15. #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? |
16. Re: #12973 |
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. |
17. #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"
CALL VALUE "var1","", "ENVIRONMENT"
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"
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"
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"
|
18. #12975 |
Yep. That's what i usually do. I set the var to a value like "no file". |
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 |