Sign in to follow this  
Followers 0
JSchmitt

Environment Variables And Run Command

8 posts in this topic

Hello,

I´m reading values from an INI File.

I read the value e.g. $var as %WINDIR%\System32\notepad.exe.

I can log this variable to a file correctly.

If I try to make the following ...

Run ($var)

I will get an error: Unable to execute the external program.

This is just an example ... i would like to call another program defined in an INI File using environment variables!

Does anyone has an idea.

Thx in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello,

I´m reading values from an INI File.

I read the value e.g. $var as %WINDIR%\System32\notepad.exe.

I can log this variable to a file correctly.

If I try to make the following ...

Run ($var)

I will get an error: Unable to execute the external program.

This is just an example ... i would like to call another program defined in an INI File using environment variables!

Does anyone has an idea.

Thx in advance.

try :

Run(@comspec & " /c " & $var,"",@SW_HIDE)

Or:

Opt("ExpandEnvStrings", 1)
Run ($var)
Edited by JdeB

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

Hello,

I have the OPT set and I tried your advice with no improvement.

I can call %TEMP% Variables set to Variables like:

$Execute = %Temp%\Hello.exe

but I can´t RUN a Command including variables read from an INI File!?

Share this post


Link to post
Share on other sites

May be if you post your script or part of your script and example of what the ini file look like. I'm sure somebody will be able to help you.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Hello,

here an example for my problem.

calc.exe will start.

notepad.exe will not start with the above mentioned error.

Does anyone knows what the problem is?

Thx in advance

Jochen

[AUT FILE]

Opt("ExpandEnvStrings", 1)

If $CmdLine[0] = 0 Then

If FileExists(@ScriptDir & "\Test.ini") Then

$ConfigFile=@ScriptDir & "\Test.ini"

Else

Exit

EndIf

Else

$ConfigFile=$CmdLine[1]

EndIf

$Path = IniRead($ConfigFile, "Settings", "Path", "%WINDIR%\SYSTEM32")

$strExecute="%WINDIR%\SYSTEM32\CALC.EXE"

Run ($strExecute)

$strExecute=$Path & "\NOTEPAD.EXE"

Run ($strExecute, $Path)

[TEST.INI FILE]

[settings]

Path=%WINDIR%\System32

Share this post


Link to post
Share on other sites

i just tested the last posted code... and it worked fine

both calc & notepad showed

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hello,

I tried it on windows xp german and windows 2003 english with autoit3.exe version

3.1.1.0 downloaded yesterday and it won´t work !?

Can anyone else test the script and report the result.

With OS Version and AutoIT3 Version.

Thanx

Jochen

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Your test is confirmed as an issue with AutoIt v3.1.1 release.

AutoIt v3.1.1 will only expand literal Environmental Strings.

e.g.

MsgBox(0, '3.1.1', '%WINDIR%')

AutoIt Beta had changes made to convert Environmental Strings within a variable also.

MsgBox(0, 'Beta', '%WINDIR%')

$Var = %WINDIR%
MsgBox(0, 'Beta', $Var)

Your issue was mentioned back in time here.

If you want to use the option of ExpandEnvStrings, I would recommend to use the beta here.

Edit:

The last code shows as literal as well, but consider it as an INIRead or RegRead into a variable instead which would not be a literal string within the script itself. The later will only work correctly in the beta.

Edited by MHz

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
Sign in to follow this  
Followers 0