Search code examples
cygwindos

Why doesn't redirecting output modify the last modified time field for target file?


I've got a bash script running in Cygwin whose output has been redirected to another file. MS-DOS exhibits this same behavior if I run the bash script as a batch job.

bash.exe &> log.txt

I know that bash.exe regularly dumps output so I'd like to just monitor the last modified time of log.txt to determine if bash.exe has hung.

Unfortunately, adding content to log.txt through redirection does not change log.txt's last modified time.

# ls -la --full-time log.txt
-r-xr-x---+ 1 user Domain Users 66455 2011-11-30 16:16:45.246664800 -0500 log.txt

Some time later...

# ls -la --full-time log.txt
-r-xr-x---+ 1 user Domain Users 66838 2011-11-30 16:16:45.246664800 -0500 log.txt

Note that even though log.txt has gotten larger, the last modified time has not changed. The last modified time is updated only when bash.exe terminates.

Ubuntu 11.04 handles this scenario, IMO, correctly.

Cygwin: CYGWIN_NT-6.1
MS-DOS: Microsoft Windows [Version 6.1.7601]


Solution

  • I'm having trouble reproducing this using just Cygwin so I'm not presenting the problem accurately. My process is to call Runtime.getRuntime.exec() within a Java process which opens cygwin/bin/bash.exe and then runs the redirection command from within the bash. From the same Java process that called exec(), I'm trying to monitor the last modified time based on what's going on in the previously called bash.exe.

    I have switched to checking the file length instead to determine if the process has hung, which is working. I guess it's some kind of scope problem.