Jump to content

Global variable inheritance


hgeras
 Share

Recommended Posts

First of all i'd like to thank Jonathan for this marvellous "hand-untier"... Really, it's easiness to use is proportional with it's capabilities...

But i have (almost) an issue....

I'd like to know , cos documentation doesn't clear that out, if global variables can be used in simultaneously running scripts/compiled scripts or even if they don't run the same time granted the fact thast no restart will be made....

e.g if i use:

Global $drive ="NOTACTIVE"

in script 1 , can i use something like :

global $drive

$drive2=drivestatus("f:\")

if $drive2=$drive then .......

in script 2 ?

cos till not i've been using clipget() and clipput() to exchange variables thru scripts...

thanx in advance!

Edited by hgeras
Link to comment
Share on other sites

  • Developers

I'd like to know , cos documentation doesn't clear that out, if global variables can be used in simultaneously running scripts/compiled scripts or even if they don't run the same time granted the fact thast no restart will be made....

e.g if i use:

Global $drive ="NOTACTIVE"

in script 1 , can i use something like :

global $drive

$drive2=drivestatus("f:\")

if $drive2=$drive then .......

in script 2 ?

cos till not i've been using clipget() and clipput() to exchange variables thru scripts...

thanx in advance!

<{POST_SNAPBACK}>

No .... not possible...

You can also use INIRead/INIWrite in stead of the clipboard....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

What is the point of EnvSet if it doesn't actually create an windows environment variable? This doesn't work...

Prog 1:
EnvSet("MYENV","this is a test")

Prog 2:
$MYENV = EnvGet("MYENV")
MsgBox(1,"",$MYENV)

Edit: It's easy enough to set them via the command line, set %%test%%=test, but how to grab them in autoit?

Edit: Seems it can be done in HKEY_CURRENT_USER\environment

Edited by Alterego
Link to comment
Share on other sites

It does create an environment variable. But environment variables have a total different meaning than what you're guessing. They are not meant to communicate with other programs, but to set an environment telling other programs where to look for its files, where to store temporary files, etc. Each program has its own environment. This means that when program B is started from program A it will get a copy of the environment that program A uses. But this copy is not updated with any changes that program A does to the environment since program A cannot change the environment of program B.

Example 1: If program A sets the environment variable X to "test" and then starts program B, program B will see the content of the variable as "test". Now program B sets the variable to "somethingelse". Program A still sees that variable X contains "test", while program B sees the content of the variable as "somethingelse".

Example 2: If program A sets the environment variable X to "test" and then starts program B, program B will see the content of the variable as "test". Now program A sets the variable to "somethingelse". Program A sees that variable X contains "somethingelse", while program B still sees the content of the variable as "test".

You see the logic? The environment is inherited from the parent process, but a program cannot change the environment of another program.

If you want to exchange data with another program, then there are severall options: temporary files (including INI-files), windows, window titles, registry. But environment variables are just not meant for this.

Edited by sugi
Link to comment
Share on other sites

But environment variables are just not meant for this.

Of course each program has it's own environment, but windows has an environment as well and those variables transcend each program's space. I'm talking about using the same ether that %%TMP%% resides in to provide a common way of storing information. This can be easily handled on the backend and thus completely transparent to the programmer (but it's not).

Link to comment
Share on other sites

Of course each program has it's own environment, but windows has an environment as well and those variables transcend each program's space.

Wrong. When logging on, windows reads some variables from the registry and creates environment variables from them. Then these variables are passed to each program started by the logon process exactly as I mentioned above.

When they would really transcend, you'd just have to change TEMP to something different and every program would use the new temp dir. But this doesn't happen. Why? Because the variables do not transcend, they are copied for each process.

Edited by sugi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...