0

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 command:

time vim test.txt 

I get

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

1 Answer 1

1

Which time are you using? The Bash builtin or the one in /usr/bin/time? If you use /usr/bin/time (and read man time) you'll find that you can log the output to a file, format the output any way you like, .... The Bash builtin time is much less capable.

1
  • Yes, I also found about that, see edit above.
    – muk.li
    Jul 27, 2017 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .