Page 1 of 1 1
Topic Options
#192938 - 2009-03-17 12:58 PM How assign the result of SHELL command to a variable ?
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
Hello,
I try in vain to initialize a kix variable with the content of a shell command.
I want to set a variable with the result of:
 Quote:
Shell '%comspec% /c ping -n 1 "$Machine" | find /i "ttl"'


I tried also to use the WshPipe UDF, but in vain.
Either with:
$pingres=wshpipe('ping -n 1 "$Machine" | find /i "ttl"',1)
OR
$pingres=wshpipe('ping -n 1 "$Machine" | find /i "ttl"')

Thanks for a rapid answer

Top
#192939 - 2009-03-17 01:24 PM Re: How assign the result of SHELL command to a variable ? [Re: yellowdog]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you need to specify the comspec for wshpipe too.
_________________________
!

download KiXnet

Top
#192940 - 2009-03-17 01:45 PM Re: How assign the result of SHELL command to a variable ? [Re: Lonkero]
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
With the comspec command, it's OK.
$pingres=wshpipe('%comspec% /c ping -n 1 "$Machine" | find /i "ttl"',1)

BUT if I want to extract display (?) the $pingres variable, the following error occurs.

 Quote:
ERROR : Error in expression: this type of array not supported in expressions.!
Script: F:\KIX Inventory\sep_machines.KIX
Line : 28





Edited by yellowdog (2009-03-17 01:52 PM)

Top
#192941 - 2009-03-17 01:52 PM Re: How assign the result of SHELL command to a variable ? [Re: yellowdog]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, what's $Machine?

if $machine is not available, your line would indeed cause the result to be nothing.
_________________________
!

download KiXnet

Top
#192942 - 2009-03-17 01:54 PM Re: How assign the result of SHELL command to a variable ? [Re: Lonkero]
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
$Machine is initialized correctly, it's extracted from a net view command.
My problem now is, how do I extrcat the content of $pingres variable ?

Top
#192943 - 2009-03-17 02:32 PM Re: How assign the result of SHELL command to a variable ? [Re: yellowdog]
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
How do I get the content of
$pingres=wshpipe('%comspec% /c ping -n 1 "$Machine" | find /i "ttl"',1)
If I perform a ? $pingres an error occurs.

If there is an other way to transfer the result of a SHELL command to a local variable, let me know.
It's rather urgent.

Top
#192944 - 2009-03-17 03:20 PM Re: How assign the result of SHELL command to a variable ? [Re: yellowdog]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
$pingres is an array not a string.

for each $line in $pingres
? $line
next

Top
#192945 - 2009-03-17 03:48 PM Re: How assign the result of SHELL command to a variable ? [Re: Allen]
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
OK Allen, it sounds good now.
Top
#192948 - 2009-03-17 05:20 PM Re: How assign the result of SHELL command to a variable ? [Re: yellowdog]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Again, the UDF Header is there as a mini-manual, and is intended to be read before use. From the header:
 Quote:
;Returns:
; Output of COMMAND in an array, ExitCode of the COMMAND in the @ERROR macro.

If you look further at the code the return is an array of lines of the combined STDOUT and STDERR results. This is actually the main reason I don't use this function. I employ a modified function that returns STDOUT & STDERR as two elements of an array, but each is a simple string. This way, I can easily examine the STDOUT or STDERR streams independently.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

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 138 anonymous users online.
Newest Members
MaikSimon, kvn317, kixtarts2025, SERoyalty, mytar
17872 Registered Users

Generated in 0.064 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

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