Announcement

Collapse
No announcement yet.

write to a .txt file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    write to a .txt file

    Hi there Seers!
    I'm desperately trying to write anything to a .txt file (or any other file for that matter)
    I tried System.IO.File.CreateText and similar thing, but somehow it does not work...
    Can anyone share a scropt to open a file and write to it?
    All help is welcome!
    Thanks!

    #2
    Here's a script that writes the Zee CPU Load Average to a file. Mine runs every :15 mins...



    PHP Code:
    Sub Main(ByVal Parms as object)

        
    dim proc as System.Diagnostics.Process
        dim resp
    ,as String
        dim ary
    () as String
        dim i 
    as Integer
        dim sw 
    as System.IO.StreamWriter

        
    Try
             
    proc = new System.Diagnostics.Process()
             
    proc.StartInfo.FileName="/usr/bin/uptime"
             
    proc.StartInfo.UseShellExecute=False
             proc
    .StartInfo.RedirectStandardOutput True
             proc
    .Start()
             
    resp=proc.StandardOutput.ReadToEnd()

             
    ary resp.Split(New Char() {","c})

             If(
    UBound(ary)>=4then
                  sw 
    = New System.IO.StreamWriter("/usr/local/HomeSeer/Data/ZeeCPUPerformance.txt",True)
                  
    sw.WriteLine(Now() & "," ary(4))
                      
    hs.SetDeviceValueByRef(62,cdbl(ary(4)),True)
                      
    hs.SetDeviceString(62,"",True)
              
    hs.SetDeviceString(62,"Load Average: " cdbl(ary(4)),True)
             
    End If

        Catch 
    ex as Exception
             hs
    .writeLog("Exception",ex.message)
        Finally
             If(
    not sw Is Nothingthen
                  sw
    .Close()
             
    End If
        
    End Try
    End Sub 
    Last edited by rmasonjr; August 19, 2016, 04:10 PM. Reason: wrong script
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      Wow! Thanks!

      Comment


        #4
        I added this script after seeing the above post and it has been helpful. I added the event running it with the "do not allow more than one script to run" option. Despite that, I noted during a restart of the Zee tons of ugly logs about the script trying to run several times in the same second, compile errors and other nasty errors. After seeing that I also added an option to the event to not re-run for 14 minutes. Hope that avoids that mess in the future.

        Comment

        Working...
        X