in reply to File::Temp problems on Win32

In windows, (by default?) a file can only be opened by one process. The $tf that File::Temp returns is a filehandle opened for writing. Your system command starts another process which tries to write to the same file, but it's locked by the first process. On *nix, more than one process can write to a file at the same time.

Replies are listed 'Best First'.
Re^2: File::Temp problems on Win32 (myth)
by tye (Sage) on Jul 30, 2008 at 01:44 UTC
    In windows, (by default?) a file can only be opened by one process.

    Um, no. The default for C programs (and Perl is a C program) is to allow other processes to read/write to a file we have open but to not allow a file that we have open to be renamed or deleted (when using open() as opposed to CreateFile() or other calls not typical of portable C programs).

    Perhaps File::Temp is locking the file. File locks in Win32 are always manditory while they default to advisory on Unix. Perhaps just ask File::Temp to not lock?

    - tye        

Re^2: File::Temp problems on Win32
by trek1s (Scribe) on Jul 29, 2008 at 16:17 UTC

    Thanks a lot for the fast response

    Does anybody know if there is a workaround or alternative for this case?

      Just use the filehandle that you have opened:
      print $tf `date /t`;