Posts: 1,031
Threads: 246
Joined: Jul 2022
11-17-2024, 01:29 AM
(This post was last modified: 11-17-2024, 01:37 AM by Davider.)
The environment variable settings in the following two macro codes interfere with each other.
For example, after macro M_A is executed, macro M_B outputs the value set by M_A.
(I have to restart QM to ensure that a single macro executes correctly.)
Because I frequently use temporary environment variables, I have encountered some strange issues before, which I believe might be related to this problem.
How can this be avoided? Thanks for Any suggestions or help
Macro
M_A
SetEnvVar "Path" "hello"
GetEnvVar "Path" _s
out _s
Macro
M_B
GetEnvVar "Path" _s
out _s
Posts: 12,071
Threads: 140
Joined: Dec 2002
For example you can create a class that restores the initial variable value in destructor.
Posts: 1,031
Threads: 246
Joined: Jul 2022
11-17-2024, 06:22 AM
(This post was last modified: 11-17-2024, 06:23 AM by Davider.)
Thanks for your suggestion.
I’m a bit confused about the temporary environment variables in QM; they don’t seem to refresh in real-time.
I’ve tried multiple times to achieve the following PowerShell results in QM, but I couldn’t figure it out.
$env:Path="world; $($env:Path)"
$env:Path
$env:Path="hello; $($env:Path)"
$env:Path
Posts: 12,071
Threads: 140
Joined: Dec 2002
;/exe
str s1
GetEnvVar "Path" s1
s1-"hello;"
SetEnvVar "Path" s1
GetEnvVar "Path" _s
out _s
Posts: 1,031
Threads: 246
Joined: Jul 2022
11-17-2024, 12:27 PM
(This post was last modified: 11-17-2024, 12:36 PM by Davider.)
Thanks for your help.
The /exe tag at the beginning of the code worked and seems to have resolved the issue I mentioned earlier.
Would it be very complicated if we avoid using the /exe tag (which generates a file) and instead use the method mentioned below?
Quote:For example you can create a class that restores the initial variable value in destructor.
Using the following WinAPI function, it seems the initial value can always be retrieved.
Posts: 12,071
Threads: 140
Joined: Dec 2002
11-17-2024, 01:06 PM
(This post was last modified: 11-17-2024, 01:13 PM by Gintaras.)
It would be a very simple class that uses GetEnvVar/SetEnvVar. Remember a variable in some member function, and restore in destructor.
Posts: 1,031
Threads: 246
Joined: Jul 2022
11-19-2024, 12:51 AM
(This post was last modified: 11-19-2024, 12:53 AM by Davider.)
Sorry, I still don’t have any ideas on how to solve this issue by creating this class.
When I use `getenv("PATH")`, the value of the PATH variable still doesn’t refresh in real-time; it’s always the initial value.
Could you share the code for this feature?
Posts: 12,071
Threads: 140
Joined: Dec 2002
11-19-2024, 05:50 AM
(This post was last modified: 11-19-2024, 05:57 AM by Gintaras.)
I would use a class with a destructor to solve the first issue in a more convenient way.
I don't know about getenv. I would use GetEnvVar and not have the second issue.