Jump to content

Environment Variables And Run Command


Recommended Posts

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.

Link to comment
Share on other sites

  • Developers

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

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

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!?

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

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

Link to comment
Share on other sites

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