Page 1 of 2

filetime and filedate in directory

Posted: Wed Aug 10, 2022 1:08 am
by Victorio
Hi,
I have some little problem, need updated filetime and filedate of some file in directory.
functions filetime() and filedate() return still some time and date when program running, but I need info about access time
when other users write to this file.
This looks to fact, that when program is running, still see directory without changes in real time.
Test program attached.

Note : I need some system to control external programs called with Runshell. I am working on system which do this :
main program call external program with runshell
when external program start , create temporary file to hdd and write to it some row for example date and time of start process
every x seconds also fopen and fclose this file to "tell" main program, that, external process still running
when process pass, this temporary file will delete or write some row for example stop at date and time

main program waiting to end of external program, and every x seconds test if temporary file exist, when no, this looks external process is ended, when exist also look to last access date and time, and when this is more than some limit, for example 30 seconds, this looks, that external process have some problem, frozen, or crashed.

But when I can not determine real access time, this not work.

Maybe I have some wrong in my test program, but this looks to not refreshing Directory() structure when XPP program running. When close and open, date and time load correct.


Thanks for all advices

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 1:26 am
by Eugene Lutsenko
Or maybe it's just when the process starts to create a file with the process ID, and when it ends to delete it?

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 2:00 am
by Victorio
Hi Eugene,
I do not understand what do you mean ?
I have one main program, and this run via Runshell several exe modules, which run on all CPU cores simultaneously.
With Runshell have not any feedback. Tasklist is not usable because process can be frozen, and for it i use "timestamp" rows in temporary file.

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 2:09 am
by Auge_Ohr
hi Victorio,
main program call external program with runshell
Runshell does not give you a Handle and so your "Problem" begin

this Code is using Ot4Xb and give you Information if you App is still running

Code: Select all

#include "ot4xb.ch"                                                                                   
// ---------------------------------------------------------------------------
proc main()
local oProcess := TRunProcess():New()
local lActive  := NIL
local dwExitCode

oProcess:cAppName := cPathCombine( GetWinDir(), "notepad.exe" )
// oProcess:cParams  := cPathCombine( cAppPath(), "TRunProcess.prg" )
// oProcess:lInheritHandles := .T.
oProcess:wShowWindow :=  oProcess:swMinimize
oProcess:lUseShowWindow := .T.
// oProcess:lCreateNewConsole := .F.
// oProcess:Cmd( "DIR > test.txt" )
if oProcess:Start()
   ? "Running " , oProcess:cAppName
   while oProcess:lTestActiveById()
     // App is running
   end
   ? "Exit Code: " , oProcess:GetExitCodeById()
you also can "Terminate" running App what this Demo Source show
TRunProcess.zip
(3.95 KiB) Downloaded 177 times
p.s. "switch" CPU before call TRunProcess() and Child App will run on that CPU even when MAIN "switch" again

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 2:33 am
by Victorio
Thank you Jimmy, i will look to it, this can be very usable for me.
I am using also other system to controlling runshell processes with DBF file, where this external processes write information about status , and main program read it , in database is fields CPU01 to CPU12 for example. Main program determine number of cores , and run this number external modules, when all fields in DBF have status "passed" complete process is passed.
Problem is , when some of external process crashed, or frozen, then main program wait and wait... .

I will look, how can use TRunprocess.

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 2:45 am
by skiman
Hi Victorio,

A solution can be to write the timestamp in the created files. If the file exists, you can check the content with a memoread. I suppose this is faster according to the directory() function.
In your main program, you can have an array which contains the time of your last check for each process. So you can check with the memoread for example each 5 seconds.

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 3:30 am
by Victorio
Chris,
Yes, I am writing to file time stamp
first when begin is text START date time
when processing, every x seconds for example every minute write text ACTIVITY date time
and when process passed, write STOP date time

then when some problem I can look or program can read from this files info about time how long processes works, also when missing STOP, this is info that process crashed or cancelled by user

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 3:40 am
by Victorio
Jimmy, please can you save attached file againg ? It cannot download, THX

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 4:12 am
by skiman
Victorio,

So my suggestion is to read the content of the file to check if the process is still running instead of using the directory() function to check the time.

Re: filetime and filedate in directory

Posted: Wed Aug 10, 2022 4:50 am
by Victorio
Ok, Chris, i work on this variant.