Jump to content

Every second a new .txt


Recommended Posts

Hi,

So yesterday with some help i made this.

$fname = "processes.txt"
$file = FileOpen($fname, 9)

$list = ProcessList()

for $i = 1 to $list[0][0]
    FileWriteLine($file, "Process Name: " & $list[$i][0] & " PID: " & $list[$i][1] & @CRLF)
next

FileClose($file)

So what i want to make is that it logs every second the procces.

I know i can wend it and sleep 1000 it but is there a way to let the $fname = "processes.txt change every time. So it becomes processes.txt then processes1.txt then processes2.txt and so on.

I have no clue how to do that.

Thnx for your time.

Link to comment
Share on other sites

This would be one way to do it.

I'm using AdlibRegister as Sleep(1000) would add to the time is takes the function to run. I don't know how precise you want it to be. Another way to do it would to check the @SEC macro and run the function when it's value changes.

AdlibRegister( "_WriteFile" ,1000)
Global $Seconds = 0

While 1
    Sleep(100)
WEnd

Func _WriteFile()
    Local $fname = "processes" & $Seconds & ".txt"
    Local $file = FileOpen($fname, 9)
    Local $list = ProcessList()
    for $i = 1 to $list[0][0]
        FileWriteLine($file, "Process Name: " & $list[$i][0] & " PID: " & $list[$i][1] & @CRLF)
    next
    FileClose($file)
    $Seconds += 1
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...