2012-02-22 109 views
3

有幾篇文章討論將時間命令輸出重定向到文件。例如如何在Mac OS X下重定向時間命令輸出

(time my_program) 2> out 

{ time my_program ; } 2> out 

他們在Linux下工作,但他們沒有在我的Mac OS X機器上使用Darwin Kernel Version 11.2.0工作。

(time my_program) 2> out 
Badly placed()'s. 

{ time my_program ; } 2> out 
{: Command not found. 
}: Command not found. 

time --version 
--version: Command not found. 
0.000u 0.000s 0:00.00 0.0%  0+0k 0+0io 0pf+0w 

/usr/bin/time --version 
/usr/bin/time: illegal option -- - 
usage: time [-lp] command. 

在我的Mac機,有殼內置time/usr/bin/time。它們都不提供-o選項。由於我的程序運行了幾天,而且我想要計時,我如何將time的輸出重定向到Mac OS X下的文件?

+0

它們以什麼方式工作?你有權限在當前工作目錄下創建'out'文件嗎?是否創建了out文件?它是空的還是包含數據?你有沒有使用'ls(1)'等小程序以及你的程序進行測試? – sarnold 2012-02-22 03:32:01

+0

試試'time my_program>&out'? – 2012-02-22 03:41:12

+0

什麼版本是/ usr/bin/time? – Rich 2012-02-22 04:56:26

回答

1

我意識到這真的很晚,但下面的命令爲我工作。

{ time ls > command.output 2>&1 ; } 2> time.out