In unix, anyone know how to capture the output from the time function to a string or file?
time convert logo: logo.gif
real 0m1.147s
user 0m0.054s
sys 0m0.069s
capturing IM processing time
Re: capturing IM processing time
to File
( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif
time -o won't work and with -o you have a different format of output
to Variable:
temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )
temp=${temp#*real?}
seconds=${temp%?user*}
( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif
time -o won't work and with -o you have a different format of output
to Variable:
temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )
temp=${temp#*real?}
seconds=${temp%?user*}
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: capturing IM processing time
thanks zaratol. it works. but that is a bit more unix than I understand. Can you explain the use of the parens in
( time convert logo: logo.gif ) 2> someReportFile.txt
and the use of the braces in the following and why they seem to have to be on different lines
temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )
Then I can go do some reading on those concepts.
Thanks
Fred
( time convert logo: logo.gif ) 2> someReportFile.txt
and the use of the braces in the following and why they seem to have to be on different lines
temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )
Then I can go do some reading on those concepts.
Thanks
Fred
Re: capturing IM processing time
One concept used here is redirection of output:
http://tldp.org/LDP/abs/html/io-redirection.html
the other is subshells:
http://tldp.org/LDP/abs/html/subshells.html
to be honest, only understand the first example myself, but because i was curious i stumbled on the second example via google
http://tldp.org/LDP/abs/html/io-redirection.html
the other is subshells:
http://tldp.org/LDP/abs/html/subshells.html
to be honest, only understand the first example myself, but because i was curious i stumbled on the second example via google

- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: capturing IM processing time
The parenthesis is not needed.zaratol wrote:to File
( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif
The 2> redirect the error channel (file descriptor number 2) to a file for the given command which is 'time' not 'convert'. However as 'time' executes the given 'convert' command, its errors will be included in the error channel for 'time'.
This also means convert and time errors are merged! however as time only outputs its info AFTER the command is finished the time results will be AFTER any errors from convert.
Alternatives...
time_results=`time convert logo: logo.gif 2>&1`
The 2>&1 here merges the error channel (2) to the normal output channel (1) so that the backticks can capture it.
And here I use a sub-shell to junk any errors from the 'convert' from the output of time.
time_results=`time bash -c 'convert logo: logo.gif 2>/dev/null' 2>&1`
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/