Page 1 of 1
Livecode and disk usage.
Posted: Tue Jul 22, 2014 5:24 pm
by zaxos
Hello, is there a way to get the disk usage and maybe cpu usage with livecode?
Thank you for your time.
Re: Livecode and disk usage.
Posted: Tue Jul 22, 2014 7:56 pm
by FourthWorld
IIRC the freesize function returns available disk space on the volume in which the directory is currently set.
For CPU or RAM statistics you'll need to call out to the OS via shell.
On Linux this stuff is easy: for processes use "top" with a one-iteration argument and parse the results, and for RAM use "free".
Top will also work on Mac, but not free; you'll have to dig up the Mac equivalent for that. On Windows the command line is so FUBAR that you'll need to use other calls, and I don't recall what they are only that it was much more onerous (as is nearly everything in an OS that doesn't ship with bash).
Re: Livecode and disk usage.
Posted: Tue Jul 22, 2014 11:47 pm
by paul_gr
Since Windows XP Pro you can use WMIC to get a LOT of details about Windows and the computer it is running on.
example -- Windows Only...
drop one field on the card and name it "fldOut"
put the script below on a button.
-------------------------------------------------------------------------
on mouseUp
set the hideConsoleWindows to true
put empty into fld "fldOut"
put "wmic cpu get loadpercentage" into tCom1
put "CPUload percent is " & line 3 of shell(tCom1) into line 1 of fld "fldout"
put "wmic os get freephysicalmemory" into tCom2
put "freephysicalmemory is " & line 3 of shell(tCom2) into line 2 of fld "fldout"
end mouseUp
-------------------------------------------------------------------------
this will get the CPU load and the free memory details.
Paul
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 12:12 am
by FourthWorld
Is WMIC available in the "Home" (non-"Pro") versions of Windows?
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 12:17 am
by paul_gr
Hi Richard,
FourthWorld wrote:Is WMIC available in the "Home" (non-"Pro") versions of Windows?
In Windows 7 and 8 -- yes.
In XP, the pro version is needed.
Paul
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 12:22 am
by FourthWorld
paul_gr wrote:Hi Richard,
FourthWorld wrote:Is WMIC available in the "Home" (non-"Pro") versions of Windows?
In Windows 7 and 8 -- yes.
In XP, the pro version is needed.
Nice. Not as nice as Cygwin, but if it doesn't need to be installed it's super-useful. Thanks.
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 12:47 am
by zaxos
Super ! this worked like a charm, never thought of shell since its blocking my whole stack, is there a way to overcome this?
Thank you again for your time !
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 2:17 am
by paul_gr
Hi Zaxos,
shell() is a blocking command, unfortunately.
One possible thing to watch for when using shell() in a corporate setting; some sysadmins block use of shell(), by disabling cmd.exe...
Paul
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 6:02 pm
by zaxos
Code: Select all
put "wmic cpu get loadpercentage > c:\log.log" into cpuLog
launch cpuLog
is there a reason this dosent work??
Code: Select all
put "cmd wmic cpu get loadpercentage > c:\log.log" into cpuLog
launch cpuLog
or this
Code: Select all
put "wmic cpu get loadpercentage > c:\log.log" into cpuLog
launch cpuLog with "cmd"
or even this
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 6:36 pm
by Klaus
Hi zaxos,
because LAUNCH is not the correct syntax, as you might have guessed after reading the other postings
Do this:
...
put "cmd wmic cpu get loadpercentage > c:\log.log" into cpuLog
put SHELL(cpuLog) into tTemp
...
Best
Klaus
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 6:44 pm
by zaxos
how bout this?
Code: Select all
// wmic cpu get loadpercentage > c:\log.log in script.bat
launch "C:\script.bat"
whys that not working too ? :/
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 6:50 pm
by Klaus
Hi zaxos,
please check the dictionary, if yomething does not works as you exspect!
But you want:
Best
Klaus
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 6:55 pm
by zaxos
nice ! well that solved it

, no more blocking and with a read from file i get an endless reading

, thank you man, and btw the dictinary usualy cofuzed me :/
Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 7:10 pm
by Klaus
zaxos wrote:... and btw the dictinary usualy cofuzed me :/
Try to make the dictionary your friend, it may be your only companion in dark, cold winter nights!

Re: Livecode and disk usage.
Posted: Wed Jul 23, 2014 7:55 pm
by zaxos
for some reason i couldent hide the cmd this way

, anyway i found a workaround with vbs script , here it is if anyone need it
Livecode:
Code: Select all
local vCancel
on mouseUp
if vCancel is true then
put false into vCancel
cpuUsage
set the label of btn "cpuStatus" to "Stop"
else
put true into vCancel
set the label of btn "cpuStatus" to "Start"
end if
end mouseUp
on cpuUsage
put "C:\cpuUsage.vbs" into theCMD
launch document theCMD
wait 100 millisec
put URL "file:C:\cpuUsage.txt" into log
put log into field 1
set itemDel to cr
set the thumbposition of scrollbar 1 to item 2 of log
put empty into URL "file:C:\cpuUsage.txt"
if vCancel is true then
-- nothing
else
send cpuUsage to me in 1 sec
end if
end cpuUsage
cpuUsage.vbs
Code: Select all
Option Explicit
Dim oWsh, oWshSysEnv, objFSO, objWMIService
Dim oDrives, oDrive, objOutFile, colItems, objItem
Dim strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse
Set oWsh = WScript.CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
strLineTime = Date() & Space(2) & Time()
'Gets PROCESSOR Usage
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime
Next
'Output to text
Set objOutFile = objFSO.OpenTextFile("C:\cpuUsage.txt", 8, True)
objOutFile.WriteLine "Processor Usage (%)"
objOutFile.WriteLine strLineProcessorTime
WScript.Quit
all you have to do is make a stack with a button named cpuUsage, a scrollbar and a field, this code updates both the field and the scrollbar and it only cancels if u press the button again
