Page 1 of 1 1
Topic Options
#127887 - 2004-10-13 11:31 PM Use results from a command line command
Mike72677 Offline
Fresh Scripter

Registered: 2004-06-17
Posts: 32
Loc: PA
I usually miss the obivious so excuse this question if it's TOO easy! I have a 3rd party command utility called UPTIME that will tell you how long a machine has been running. The command line is very simple UPTIME SERVERNAME How can I use that command and store the results as a value? I tried the obivious Code:
 $X = SHELL '%COMSPEC% /c UPTIME SERVERNAME' 

But that doesn't work. What's the quick, easy solution I'm missing? I want to check a few servers using a looping script and store each output to use in a message box. I have the rest of the script to do what I need. I'd rather not do this by creating a temporary output file if I can. Thanks!

Top
#127888 - 2004-10-13 11:45 PM Re: Use results from a command line command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
commands do not return any value.
sorry.

but in the udf library there is uptime function (UDF) that does.
_________________________
!

download KiXnet

Top
#127889 - 2004-10-13 11:56 PM Re: Use results from a command line command
Cybex Offline
Getting the hang of it
*****

Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
I know this is not what you asked but is the Uptime() UDF not an option?
_________________________
Common sense isn't so common.

Top
#127890 - 2004-10-13 11:58 PM Re: Use results from a command line command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
asking from me?
_________________________
!

download KiXnet

Top
#127891 - 2004-10-13 11:58 PM Re: Use results from a command line command
Cybex Offline
Getting the hang of it
*****

Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
Woops, Jooel beat me to the post. You snooze you lose around here.
_________________________
Common sense isn't so common.

Top
#127892 - 2004-10-14 12:05 AM Re: Use results from a command line command
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are low-tech options as well. You could redirect to a file and read it back or pipe it with one of the pipe UDFs.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#127893 - 2004-10-14 01:53 AM Re: Use results from a command line command
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And the original question is even answered in the RUN/SHELL FAQ.
_________________________
There are two types of vessels, submarines and targets.

Top
#127894 - 2004-10-14 06:35 PM Re: Use results from a command line command
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
if you can't use the udf for whatever reason, check this out. i use uptime in a kixform, so the return value is dumped into a listview. but you should be able to pick at it or at least get an idea of how to pipe it. pipe() function is Shawn's.

Code:

function GetUpTime($comp)
dim $arrName, $shell, $ret[7,1]
$arrName = "Current system uptime","System Availability","Total Uptime",
"Total Downtime", "Total Reboots","Mean Time Between Reboots",
"Total Bluescreens", "Since"

$shell = 'uptime /s ' + $comp + ' | find '
for $j = 0 to ubound($arrName)
$cur = pipe($shell + '"' + $arrName[$j] + '"')
if ubound($cur) >= 0
$pos = instr($cur[0],":")
$ret[$j,0] = trim(substr($cur[0],1, $pos-1))
$ret[$j,1] = trim(substr($cur[0], $pos+1))
else
$ret[$j,0] = $arrName[$j]
endif
next
$GetUpTime = $ret
endfunction

;------------------------------------------------------------------------------------------------------------

function pipe($command)
dim $i,$error,$line
dim $array[255]
dim $redim $redim = ubound($array)
dim $tempfile $tempfile = "%temp%\pipe.tmp"
if exist("$tempfile")
del("$tempfile")
endif
if @inwin = 2 ; win9x
shell '%comspec% /c $command >"$tempfile"'
else ; winnt
shell '%comspec% /c $command >"$tempfile" 2>nul'
endif
$error=@error
if open(10,"$tempfile") = 0
$i=0
$line = readline(10)
while not @error
if $line
$array[$i] = $line
if $i = $redim
$redim=$redim*2
redim preserve $array[$redim]
endif
$i=$i+1
endif
$line = readline(10)
loop
$=close(10)
del "$tempfile"
if $i > 0
redim preserve $array[$i-1]
$pipe=$array
else
$pipe = 0
endif
exit $error
else
$pipe = 0
exit @error
endif
endfunction



Here's one way you could use it as is.

Code:

$UPTIME = GetUpTime($ComputerName)
for $j = 0 to ubound($UPTIME)
? $UPTIME[$j,0] " : " $UPTIME[$j,1]
next

_________________________
Eric

Top
#127895 - 2004-10-15 07:52 AM Re: Use results from a command line command
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Sounds like a dandy place for WSHPIPE() UDF.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#127896 - 2004-10-16 03:07 PM Re: Use results from a command line command
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
IIRC, one can even retrieve uptime events from the Event Log or the "heartbeat" registry key (upodated in 5-minute increments).
_________________________
There are two types of vessels, submarines and targets.

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 978 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.06 seconds in which 0.025 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