#132872 - 2005-01-24 05:10 PM
commands with vars from an ini-file
|
Anonymous
Anonymous
Unregistered
|
Hi,
I want to make a script that reads an ini-file in which there are commands. Those commands have to be executed. No problem when I use drive-letters: s:\calc.exe But in one command there is an environment variable (%qlserver%) which contains \\server1. So I want to execute %qlserver%\store\calc.exe
But nothing happens. The "shell $cmd" isn't executed in the line with the %qlserver%. When I put an '? $cmd' in front of it I can see the right command.
So I have an logon.ini file with %qlserver%\store\calc.exe
and a test.kix with If Open (1,@LSERVER + "\store\logon.ini",2) = 0 $cmd = ReadLine(1) While @ERROR <> -1 ;eof Shell $cmd $cmd = ReadLine(1) Loop $ = Close (1) EndIf
What am I doing wrong?
|
|
Top
|
|
|
|
#132873 - 2005-01-24 05:26 PM
Re: commands with vars from an ini-file
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Checking the manual yields:
ExpandEnvironmentVars( )
Action: Expands any environment variables inside a string to the corresponding plain text value. Syntax: EXPANDENVIRONMENTVARS ("string") Parameter: String The string you want to expand. Returns: The expanded string. Example: $Value = ReadValue( "HKLM\System\CurrentControlset\Control\Windows", "SystemDirectory") ? ExpandEnvironmentVars( $Value )
|
|
Top
|
|
|
|
#132875 - 2005-01-24 09:28 PM
Re: commands with vars from an ini-file
|
Anonymous
Anonymous
Unregistered
|
Already tried. $cmd contains %qlserver%\store\calc.exe but does not execute within the shell-command.
|
|
Top
|
|
|
|
#132876 - 2005-01-24 11:20 PM
Re: commands with vars from an ini-file
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
You could try using the Execute() function to translate any macros/vars or env-vars to text.
Your test.kix should then be like this: Code:
If Open (1,@LSERVER + "\store\logon.ini",2) = 0 $cmd = ReadLine(1) While @ERROR = 0 ;eof $RC = Execute('$$cmd=$cmd') Shell $cmd $cmd = ReadLine(1) Loop $ = Close (1) EndIf
-Erik
|
|
Top
|
|
|
|
#132877 - 2005-01-25 10:51 AM
Re: commands with vars from an ini-file
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Already tried.
$cmd contains %qlserver%\store\calc.exe but does not execute within the shell-command.
Did you try to run under %COMSPEC%? You will need to do this if you want to expand environment variables on the command line.
You also need to ensure that the environment variable is available - it depends on how you set it.
You will also need to protect the command path if it contains spaces.
Your SHELL command should look like this:
Code:
Shell '"'+%COMSPEC%+'" /C "'+$cmd+'"'
If @ERROR "Got error in SHELL: ["+@ERROR+"] "+@SERROR+@CRLF EndIf
|
|
Top
|
|
|
|
#132878 - 2005-01-26 09:46 PM
Re: commands with vars from an ini-file
|
Anonymous
Anonymous
Unregistered
|
thanx to you all I have a part of the solution: Shell("%comspec% /c " + $test) does it! Thank you very much!
And do you also have a solution if there is a kix-macro in the ini-file:
@scriptdir\calc.exe
Also this one won't run. Here I can't use the comspec-trick. @scriptdir\calc.exe has to be executed as c:\temp\calc.exe.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 611 anonymous users online.
|
|
|