Livecode and disk usage.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Livecode and disk usage.
Hello, is there a way to get the disk usage and maybe cpu usage with livecode?
Thank you for your time.
Thank you for your time.
Knowledge is meant to be shared.
-
- VIP Livecode Opensource Backer
- Posts: 10058
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Livecode and disk usage.
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).
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).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Livecode and disk usage.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10058
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Livecode and disk usage.
Is WMIC available in the "Home" (non-"Pro") versions of Windows?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Livecode and disk usage.
Hi Richard,
In XP, the pro version is needed.
Paul
In Windows 7 and 8 -- yes.FourthWorld wrote:Is WMIC available in the "Home" (non-"Pro") versions of Windows?
In XP, the pro version is needed.
Paul
Last edited by paul_gr on Wed Jul 23, 2014 12:24 am, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 10058
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Livecode and disk usage.
Nice. Not as nice as Cygwin, but if it doesn't need to be installed it's super-useful. Thanks.paul_gr wrote:Hi Richard,In Windows 7 and 8 -- yes.FourthWorld wrote:Is WMIC available in the "Home" (non-"Pro") versions of Windows?
In XP, the pro version is needed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Livecode and disk usage.
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 !
Thank you again for your time !
Knowledge is meant to be shared.
Re: Livecode and disk usage.
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
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.
Code: Select all
put "wmic cpu get loadpercentage > c:\log.log" into cpuLog
launch cpuLog
Code: Select all
put "cmd wmic cpu get loadpercentage > c:\log.log" into cpuLog
launch cpuLog
Code: Select all
put "wmic cpu get loadpercentage > c:\log.log" into cpuLog
launch cpuLog with "cmd"
Knowledge is meant to be shared.
Re: Livecode and disk usage.
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
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.
how bout this?
whys that not working too ? :/
Code: Select all
// wmic cpu get loadpercentage > c:\log.log in script.bat
launch "C:\script.bat"
Knowledge is meant to be shared.
Re: Livecode and disk usage.
Hi zaxos,
please check the dictionary, if yomething does not works as you exspect!
But you want:
Best
Klaus
please check the dictionary, if yomething does not works as you exspect!

Code: Select all
launch "C:\an_app.EXE"
Code: Select all
launch DOCUMENT "C:\script.bat"
Best
Klaus
Re: Livecode and disk usage.
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 :/


Knowledge is meant to be shared.
Re: Livecode and disk usage.
Try to make the dictionary your friend, it may be your only companion in dark, cold winter nights!zaxos wrote:... and btw the dictinary usualy cofuzed me :/



Re: Livecode and disk usage.
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:
cpuUsage.vbs
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 

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
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

Knowledge is meant to be shared.