Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Temporary Environment Variables Between Macros
#1
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
 
Code:
Copy      Help
SetEnvVar "Path" "hello"
GetEnvVar "Path" _s
out _s

Macro M_B
Code:
Copy      Help
GetEnvVar "Path" _s
out _s
#2
For example you can create a class that restores the initial variable value in destructor.
#3
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.
 
Code:
Copy      Help
$env:Path="world; $($env:Path)"
$env:Path
$env:Path="hello; $($env:Path)"
$env:Path
#4
Code:
Copy      Help
;/exe
str s1
GetEnvVar "Path" s1
s1-"hello;"
SetEnvVar "Path" s1
GetEnvVar "Path" _s
out _s
#5
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?  Smile
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.

Code:
Copy      Help
out getenv("PATH")
#6
It would be a very simple class that uses GetEnvVar/SetEnvVar. Remember a variable in some member function, and restore in destructor.
#7
Sorry, I still don’t have any ideas on how to solve this issue by creating this class.   Huh

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?
#8
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.
#9
Quote:I would use a class with a destructor to solve the first issue in a more convenient way.
 Could you share the code for this class? Ever since I started using QM, the issue of "environment variables affecting each other between functions" has always troubled me.
My solution has been to use PowerShell code related to the variables, but it's not elegant and runs slowly.
Anyway, thank you very much!
#10
https://www.libreautomate.com/forum/show...p?tid=7781


Forum Jump:


Users browsing this thread: 1 Guest(s)