Skip to content
⌘ NSIS Forum Archive

Check if file is closed

4 posts

Dizzy007#

Check if file is closed

Hi !

I'm looking for a funktion to check if a file is closed.
For example :
I execute in a command shell something like
ping xxx.xxx.xxx.xxx > server.txt

So, it takes a few secondes to get the information and close the file.
Now i want to read the file to check if my server response.
But on my slow notebook it takes too long ...
Now i want to wait till the file is closed.

Does anyone have an idea?

Thanks
Dizzy
Dizzy007#
Originally posted by kichik
Use ExecWait to wait for the command to finish 😉
ExecWait fires my command - but if there are file actions it will not wait till closing my file ... depends on my slow harddrive ;-(

I've got a workaround using a little bit code of "FileSizeNew" (see below) ...
Not the best way (i think) but it works 😛

Function ping  ; get server answer to file
  ExecWait '$TEMP\runh.exe "$TEMP\serv.bat"'
  loop1:
    IfFileExists "$TEMP\serv.txt" next1 loop1
  next1:
    Push "$TEMP\serv.txt"
    Call FileSizeNew
    Pop $0
    IntCmp $0 250 next1 next1 next2
  next2:
Functionend
function FileSizeNew
  Exch $0
  Push $1
  FileOpen $1 $0 "r"
  FileSeek $1 0 END $0
  FileClose $1
  Pop $1
  Exch $0
functionend 
Better ideas?

Greets
Dizzy
kichik#
nsExec should soon have the process return value pushed to the stack. It should do the trick, no need writing the output to any file, just check the return value.