Page 1 of 1 1
Topic Options
#39254 - 2003-04-16 03:25 PM Output from a command to a Environment Variable (SET)
Shinji Offline
Lurker

Registered: 2003-04-16
Posts: 3
I'm writing a script to scan multiple computers (using WMI and looking into the registry) and get
information like: installed programs, startup programs, locally logged user, etc.

I'm using the fping command to check if all the PC that I have in my list (or array) are connected to the lan. I'm using Fping because the ouput is a lot more readable than Ping (parameter to display only 1 line at the ouput). So I firstly wanted to ouput the result of the Fping to a text file then read the text file and check if it contains the string 'Reply'. If it does, then I stat querying all sort of stuff to the Host I fpinged. If it contains 'Host' or something else, it means the computer is off or does not exists, so I will skip this computer.

I wanted to optimize the speed of the fping (and avoid using temp files) by ouputing the result to a dos variable. To do this, I use:
--> For /F %a in ('fping HOSTNAME -w20 -t1 -n1 -l') do SET fping_result=%a
or from Kix:
--> shell "%comspec% /C For /F %a in (" + CHR(39) + "fping " + $current_computer + " -w20 -n1 -l" + CHR(39) + ") do SET fping_result=%a"

This works fine, but it seems to create the variable in a Environement that disappears right
after the command is completed, so I can't get the variable value back.

Launched from a dos prompt (without Kix), the variable is there.

Any suggestion?

Thanks.

Shinji.

Top
#39255 - 2003-04-16 03:27 PM Re: Output from a command to a Environment Variable (SET)
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Shinji San,

please consider to use Ping() (UDF) to check whether a remote host replies [Smile]

[ 16. April 2003, 15:31: Message edited by: jpols ]
_________________________



Top
#39256 - 2003-04-16 03:27 PM Re: Output from a command to a Environment Variable (SET)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
use Ping() UDF -> http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000012

it deals with all the stuff you need and you don't need to re-invent the wheel. [Wink]
_________________________
!

download KiXnet

Top
#39257 - 2003-04-16 03:27 PM Re: Output from a command to a Environment Variable (SET)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This is not the proper forum for this post. {edit} This was originally posted to the UDF forum. {/edit}

[ 16. April 2003, 16:12: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#39258 - 2003-04-16 03:36 PM Re: Output from a command to a Environment Variable (SET)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes this is [Razz]

hehee!
_________________________
!

download KiXnet

Top
#39259 - 2003-04-16 03:36 PM Re: Output from a command to a Environment Variable (SET)
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Topic was moved to starters forum which fits better even if you don't look like a starter [Wink]

Oh yeah, I forgot to mention :

Welcome to the Board [Smile]
_________________________



Top
#39260 - 2003-04-16 03:39 PM Re: Output from a command to a Environment Variable (SET)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The manual very clearly explains how KiX accesses the environment, so what you experience is expected behavior.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#39261 - 2003-04-16 03:55 PM Re: Output from a command to a Environment Variable (SET)
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
As Les has intimated this is to do with environment variable scope, and is not specific to KiXtart, indeed it will happen with DOS shells.

Try the following:
  • Open a command line (DOS) window.
  • Type "SET VAR1=foo"
  • Type "SET" - you will see your VAR1
  • Type "%COMSPEC%" - this will start a new interpreter.
  • Type "SET VAR2=bar"
  • Type "SET" - you will see both VAR1 and VAR2
  • Type "exit" - this will close the top level interpreter
  • Type "SET" - You will only see your VAR1 environment variable.
This happens because environment variables are copied to new environments (inherited), but cannot change the environment of the process that started them.
When you "SHELL" or "RUN" a command a new environment is created. This environment can inherit environment variables from its parent, but cannot change its parents environment.

You can always echo the result to a file and read the file in KiXtart if you wish.

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 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.055 seconds in which 0.024 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