Page 1 of 1 1
Topic Options
#33277 - 2002-11-22 06:46 PM How to get environ variables from a shell command ?
Willou Offline
Fresh Scripter

Registered: 2002-11-22
Posts: 6
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

Top
#33278 - 2002-11-22 06:48 PM Re: How to get environ variables from a shell command ?
Willou Offline
Fresh Scripter

Registered: 2002-11-22
Posts: 6
Well i forgot :

script runs under WinNT/Win2K

Top
#33279 - 2002-11-22 06:58 PM Re: How to get environ variables from a shell command ?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
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 ]
_________________________
There are two types of vessels, submarines and targets.

Top
#33280 - 2002-11-22 08:06 PM Re: How to get environ variables from a shell command ?
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
...RTFM...
code:
$Y = "And this is how you access environment variables: %USERNAME%..."

_________________________
We all live in a Yellow Subroutine...

Top
#33281 - 2002-11-22 08:16 PM Re: How to get environ variables from a shell command ?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
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.
_________________________
!

download KiXnet

Top
#33282 - 2002-11-22 09:59 PM Re: How to get environ variables from a shell command ?
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
yah, playing with envars is kinda like living on a dead-end one-way street... [Roll Eyes]
_________________________
We all live in a Yellow Subroutine...

Top
#33283 - 2002-11-24 07:28 PM Re: How to get environ variables from a shell command ?
Willou Offline
Fresh Scripter

Registered: 2002-11-22
Posts: 6
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

Top
#33284 - 2002-11-24 09:52 PM Re: How to get environ variables from a shell command ?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Don't call the bat from KiX. Call it from logon.bat before you call KiX.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33285 - 2002-11-24 09:55 PM Re: How to get environ variables from a shell command ?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
See also, this:

Topic: Setting Environment Variables with SET
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#33286 - 2002-11-25 08:21 AM Re: How to get environ variables from a shell command ?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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
_________________________



Top
#33287 - 2002-11-26 12:10 AM Re: How to get environ variables from a shell command ?
Willou Offline
Fresh Scripter

Registered: 2002-11-22
Posts: 6
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
)
###

Top
#33288 - 2002-11-26 12:25 AM Re: How to get environ variables from a shell command ?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
so, isn't this same when you call the nettime.bat which does the calculation, where do you need time kixscript?
_________________________
!

download KiXnet

Top
#33289 - 2002-11-26 12:27 AM Re: How to get environ variables from a shell command ?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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 ]
_________________________



Top
#33290 - 2002-11-25 01:40 PM Re: How to get environ variables from a shell command ?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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()
_________________________



Top
#33291 - 2002-11-25 01:50 PM Re: How to get environ variables from a shell command ?
Willou Offline
Fresh Scripter

Registered: 2002-11-22
Posts: 6
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

Top
#33292 - 2002-11-25 02:05 PM Re: How to get environ variables from a shell command ?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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 ]
_________________________



Top
#33293 - 2002-11-25 06:29 PM Re: How to get environ variables from a shell command ?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#33294 - 2002-11-26 02:18 PM Re: How to get environ variables from a shell command ?
Willou Offline
Fresh Scripter

Registered: 2002-11-22
Posts: 6
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

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 353 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.066 seconds in which 0.021 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