Jump to content

EnvGet() don't get a user defined variable


Recommended Posts

Hello.

I have created a batch to suit our needs in our systems, and this batch generates some variables. The problem is: AutoIt don't recognize the variables the batch created, only Windows variables! In a example:
batch:

 

@echo off
set my_var=test

AutoIt
 

$name_test = EnvGet("my_var")
MsgBox($MB_SYSTEMMODAL, "", "The variable has the value of: " & @CRLF & @CRLF & $name_test)

It returns nothing!

But, if I change 'my_var' in AutoIt part with a Windows variable, like PATH, SYSTEMDIR, etc, it retrieves the correct variable!

How I can get my variables inside autoit?

Thanks!

Link to comment
Share on other sites

  • Developers

How is that batchfile ran to set the Environment variable in relation to when the AutoIt3 script is ran?

Jos

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

  • Developers

Ok, but how are you running it? Because when shelling the batchfile, the environment variables created by the SET command will only live during the execution of the batch file, not in any other shelled program ...right?

Jos 

Edited by Jos

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

The batch sets the variables, the runs some programas, including the autoit script. Like this:

@echo off
set my_var1="test1"
set my_var2="test2"

start /w autoit_compiled_script.exe

So, as you can see, the batch still alive when the script is called! The autoit_compiled_script.exe make use of my_var1 and my_var2!

Link to comment
Share on other sites

So, I get my variable inside AutoIt with another metodh, but I wanna learn how to read the variable directly.

I used this:

@echo off
set my_var=test1

echo %my_var% >variable1

start /w autoit_compiled_script.exe

Inside AutoIt script, I have this:

FileOpen("c:\program_folder\variable1")
Local $nome_logmein =  FileRead("c:\program_folder\variable1")
FileClose("c:\program_folder\variable1")

 

Link to comment
Share on other sites

  • Developers

Just tested with your batchfile and this in the compiled script

MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & 'EnvGet("my_var")' & @CRLF & @CRLF & 'Return:' & @CRLF & EnvGet("my_var")) ;### Debug MSGBOX

works just fine.

Jos

Edited by Jos

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

  • Developers

This one and not really using the created file:

@echo off
set my_var=test1

echo %my_var% >variable1

start /w autoit_compiled_script.exe

Jos

Edited by Jos

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

I'm feeling really stupid.

I type some wrong code into script, so when I test script itself throught Editor, it don't get the variable.

With the right code, and running the script as executable, it returns the value of my variable correctly.

Thanks for the help, and sorry for my mistake.

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...