Page 1 of 1 1
Topic Options
#132872 - 2005-01-24 05:10 PM commands with vars from an ini-file
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 Offline
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 )
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#132874 - 2005-01-24 05:27 PM Re: commands with vars from an ini-file
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Well, you don't really have an ini type of file there, just a text file you call *.ini, is it ?

Anyway, what happens if you add a command interpreter to that line like

%ComSpec% /c %qlserver%\store\calc.exe


[edit: or work with ExpandEnvironmentVars() as Howard suggests, depending on what you try to shell in real (I guess it is not calc.exe ]


Edited by Jochen (2005-01-24 05:31 PM)
_________________________



Top
#132875 - 2005-01-24 09:28 PM Re: commands with vars from an ini-file
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 Offline
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 Offline
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
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
#132879 - 2005-01-27 01:29 AM Re: commands with vars from an ini-file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
SHELL is not a function so the parens () are superfluous.
Shell '%comspec% /c ' + $test ;does it!

The solution to the macro may be to Execute() it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#132880 - 2005-01-27 01:32 AM Re: commands with vars from an ini-file
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
If you read macros in from a file (ini or not) you will treat this data in string variables (or an array of strings), so you have to double the @-character in in your input file (@@scriptdir).

Quote from the manual :

Quote:

Note: The characters @, %, or $ are normally used to indicate macros, environment strings, or variables. If you want to use these characters in a string, use @@, %%, or $$.


_________________________



Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 611 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.066 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org