Willou
(Fresh Scripter)
2002-11-22 06:46 PM
How to get environ variables from a shell command ?

Hi,

In a kix script, i launch a batch file with the SHELL command.

For ex :SHELL "%COMSPEC% /C toto.bat"

The batch file initializes some environment variables.

Then i want to work with these variables in the rest of the kix script.

What is the best way of doing to have what i look for ?

ATM i can't get back the environnement variables... [Frown]

Thankx for any help

Willou


Willou
(Fresh Scripter)
2002-11-22 06:48 PM
Re: How to get environ variables from a shell command ?

Well i forgot :

script runs under WinNT/Win2K


Sealeopard
(KiX Master)
2002-11-22 06:58 PM
Re: How to get environ variables from a shell command ?

You might want to read the KiXtart Manual, commands EXPANDENVIRONMENTVARS, SET, SETL, SETM.

Why not use KiXtart variables directly?

[ 22. November 2002, 18:59: Message edited by: sealeopard ]


Waltz
(Seasoned Scripter)
2002-11-22 08:06 PM
Re: How to get environ variables from a shell command ?

...RTFM...
code:
$Y = "And this is how you access environment variables: %USERNAME%..."



LonkeroAdministrator
(KiX Master Guru)
2002-11-22 08:16 PM
Re: How to get environ variables from a shell command ?

waltz, that most likely is not the solution as sets done in child do not get into the script (RTFM)

including the batch-file in your script would seem to be the best solution.


Waltz
(Seasoned Scripter)
2002-11-22 09:59 PM
Re: How to get environ variables from a shell command ?

yah, playing with envars is kinda like living on a dead-end one-way street... [Roll Eyes]

Willou
(Fresh Scripter)
2002-11-24 07:28 PM
Re: How to get environ variables from a shell command ?

so...

"You might want to read the KiXtart Manual,
commands EXPANDENVIRONMENTVARS, SET, SETL, SETM."

->yeah i know them and they dont do anything for me in this case..Except perhaps ëxpandenvironmentvars
as i havent got time to test it.

"Why not use KiXtart variables directly?"

-> because i want to get environment variable created BY the batch file...

"$Y = "And this is how you access environment variables: %USERNAME%..."

-> And this is how it doesnt works in this case...

"waltz, that most likely is not the solution as sets done in child do not get into the script (RTFM)
including the batch-file in your script would seem to be the best solution."

-> Lonkero is the winner !! He understood my problem....Well i dont know how to do the same in kixstart as it is in the batch file :/

In fact, the bacth file get me the hour and minute of a machine on the network (net time command)
After i do some calculation on the minute/hour in my kix script.

So any solution to this ?

Thgkx again for ur contribution


Les
(KiX Master)
2002-11-24 09:52 PM
Re: How to get environ variables from a shell command ?

Don't call the bat from KiX. Call it from logon.bat before you call KiX.

Les
(KiX Master)
2002-11-24 09:55 PM
Re: How to get environ variables from a shell command ?

See also, this:

Topic: Setting Environment Variables with SET


JochenAdministrator
(KiX Supporter)
2002-11-25 08:21 AM
Re: How to get environ variables from a shell command ?

Willou,

you can always post the batch and your kix script here asking for a translation to single KiX script ... I am quite sure the gang will take this as challenge [Big Grin]

Jochen


Willou
(Fresh Scripter)
2002-11-26 12:10 AM
Re: How to get environ variables from a shell command ?

So....

LLigetfa : it is not a logon script (i am examining ur link about environ variables).

For "the gang", here is my challenge (nothing to win except my congratulations !) [Wink]

The kix script :

####
$server = "x031768"

SHELL "%COMSPEC% /C nettime.bat $server"

? "HOUR = %HH%"
? "Minutes = %MM%"
####

The batch file (nettime.bat) :

###
for /F "TOKENS=7,8 delims=: " %%a in ('net time \\%1') do (
set HH=%%a
set MM=%%b
)
###


LonkeroAdministrator
(KiX Master Guru)
2002-11-26 12:25 AM
Re: How to get environ variables from a shell command ?

so, isn't this same when you call the nettime.bat which does the calculation, where do you need time kixscript?

JochenAdministrator
(KiX Supporter)
2002-11-26 12:27 AM
Re: How to get environ variables from a shell command ?

Here u go :

code:
break on

$server = "x031768"
$tmp = @scriptdir + "\" + @ticks + ".tmp"

shell '%ComSpec% /c net time \\' + $server + ' >' + $tmp

$ = open(1,$tmp)
if not @error
$time = readline(1)
if instr($time, ':')
$h = val(substr($time,instr($time,':')-2, 2))
$m = val(substr($time,instr($time,':')+1, 2))
$p = right($time, 2)
"Hour = " + $h ?
"Minutes = " + $m ?
"period = " + $p
else
"Net time on " + $server + " failed ..."
endif
$ = close(1)
del $tmp
endif

get $

don't know if period is a proper name for PM / AM (we calculate here with 24 hrs [Razz] )

[ 25. November 2002, 13:40: Message edited by: jpols ]


JochenAdministrator
(KiX Supporter)
2002-11-25 01:40 PM
Re: How to get environ variables from a shell command ?

Willou,

ammended above to return values rather than strings !

If you want to calculate with it later on this could be of interest for you : SerialTime()


Willou
(Fresh Scripter)
2002-11-25 01:50 PM
Re: How to get environ variables from a shell command ?

Thkx for ur contribution.

jpol : i already think about using file but....i would prefer without [Wink]

In fact, i use the kixstart to :

- read a server list
- test access to the server
- make access (with account) to the server
- launch a batch to get time of the server (no equivalent command in kix)
- calculate TIME + xx minutes more (in kix thats why i want)
- schedule a job on server with TIME + XX minutes (via AT.exe (no equivalent command in kix so will be with a batch file too)
- get @error to know if batch files goes well or not.

If no solution for getting environment variables from the batch file, i will do all the rest of the kixstart script in a batch file (net time / calculation / schedule /etc.).

Willou

End


JochenAdministrator
(KiX Supporter)
2002-11-25 02:05 PM
Re: How to get environ variables from a shell command ?

Willou,

there is no way (yet) to get back variables from shelled commands without tempfiles
(Except you have WSH installed, then you can use WshPipe())

Think batch is a pain in the a** , I would rather pipe to files than use batch , but thats only my opinion [Big Grin]

By the way : be careful when adding x minutes to a given time (full hrs etc)

Here is what I'v done in the latest SP distribution script using SerialTime() :

code:
$time = left( SerialTime( ( SerialTime($rtime) + SerialTime("00:10:00") ) ) , 5)

translated: returns the hh:mm part of serialtime (remotes actual+10 mins)

hth
Jochen

ps.: you can SHELL your at command with kix; it will set @error to 0 if successful !

pps: Caution - at works in 24 hr format so if time is PM you have to manipulate it once more [Big Grin]

[ 25. November 2002, 14:17: Message edited by: jpols ]


Sealeopard
(KiX Master)
2002-11-25 06:29 PM
Re: How to get environ variables from a shell command ?

Use the ScheduleTask() UDF to schedule tasks via the Task Scheduler on remote PCs. A lot of functionality is provided to KiXtart through UDFs if there is no native KiXtart function!

You might also want to take a look at the KiXtart systems Manaement server threads.

Everything you do can be done with pure KiXtart and the help of COM/ADSI.


Willou
(Fresh Scripter)
2002-11-26 02:18 PM
Re: How to get environ variables from a shell command ?

Hi

jpols : dont care about calculation on time [Wink] . the purpose of the script (atm) is to schedule a batch file between 5 and 30 mn more than remote time. So no need to calculate AM/PM (i only get back this statement to use it in the schedule process).

sealeopard : Effectively, i began to look in the UDF library. There a re a lot of helpful function that looked for before.

Thkx for ur help all

Willou