Assuming I want to track the times I spend editing a set of files, and log them to a file, as I could do from the commandline using the
time vim test.txt
real 0m8.149s user 0m0.056s sys 0m0.008s
Fine. Now if I want to append its output to a log file,
time vim test.txt >> my.log
Well, of course I'd make that more elaborate eventually to give me more information, but I don't get past the first step, the terminal just hangs with the following warning:
Vim: Warning: Output is not to a terminal
The redirection interferes with vim needing the terminal. What would be a good workaround here?
Edit: One workaround could be the following:
time gnome-terminal -x vim test.txt >> my.log
Which opens a new terminal window in which vim is executed. I'd prefer to stay in the same window, but could also live with this workaround.
Edit: Didn't quite work either, it seemed to do in some test, in some other it backgrounded, thus not measuring the time used. In my script now I did something like that:
/usr/bin/time -o tmpfile vim test.txt echo some stuff `cat tmpfile` some more stuff >>my.log rm tmpfile
Seems to work.
Edit: It works only as long as one doesn't have two processes using the same
tmpfile. In order to avoid that one can use the pid of the script being executed as part of the temporary file name:
/usr/bin/time -o $$.tmp vim test.txt echo some stuff `cat $$.tmp` some more stuff >>my.log rm $$.tmp