Redirecting "time" command output to file in Cygwin

1

I'm trying to redirect the result of "time" command in Cygwin to a file, and I'm not sure how to do it. I've tried time app.exe > /file/path/file.txt, (time app.exe) > /file/path/file.txt, time > /file/path/file.txt app.exe , and so on.. Frankly, whatever I could think of.

All of the above either output app.exe (which is just a stupid app that prints a few characters) to file.txt, and not the time it took to run..

also tried with -o, but it bash: -o command not found

So, how should I do it? And is the usage of a full path a problem?

Ysch

Posted 2013-09-01T13:26:56.803

Reputation: 135

Answers

3

There are two problems here, one is that time prints to STDERR (standard error) not STDOUT (standard output) so you will need to redirect that. This is done using this notation: 2>. The other problem is that time runs another command and you need to separate the two.

The solution is to use a subshell ( ) and you had it almost right:

(time app.exe ) 2> \file\path\file.txt

or

time ( app.exe ) 2> \file\path\file.txt

terdon

Posted 2013-09-01T13:26:56.803

Reputation: 45 216

Never would have guessed that.. – Ysch – 2013-09-01T13:41:15.720