The file tempfile command creates a temp file and *also returns a
writable channel handle to that file*. The fact that the file is open
means that other processes (git in your case) cannot write to it. Before
execing git, you need to close the channel handle returned, something like
close [file tempfile stdErrFile]
exec git status 2>$stdErrFile
Alternatively, you can also pass the temp file channel descriptor.
Something like
set fd [file tempfile]
exec git status 2>@$fd
seek $fd 0; # Go back to beginning of file
read $fd; # and read error messages
close $fd
Here the temp file will be automatically deleted on the close $fd
because the second stdErrFile arg to [file tempfile] is not specified
(although you could if you wanted to preserve the file). Whether you
want this or not depends on your use case.
The second method happens to have the advantage that the temp file will
not be accidentally removed by some disk cleaner before the child
process is exec-ed. Very low probability of course.
/Ashok