romulocarlos

EnvGet() don't get a user defined variable

12 posts in this topic

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!

Share this post


Link to post
Share on other sites



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

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks for fast reply.

It runs as administrator privilegies. The AutoIt scritp runs as administrator, also.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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!

Share this post


Link to post
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")

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks... But you mean the batch in first post, or the last, wich uses a file to store the variable?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks... But don't work for me. Bellow "returns" appears a blank space...

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

edit: oops, already solved, long day.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
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