在 Mac osx 上的 shell 脚本中设置标准输出缓冲区的大小



我在Mac上运行乐器,我想将输出重定向到文件。

以下是我正在使用的命令:

instruments -t "$AUTOMATION_TEMPLATE" "${APP_UNDER_TEST}" -e UIASCRIPT "AppTests/Automation/iPhone/MemLeaksTest.js" >> ${INSTRUMENTS_LOG_FILE}

现在,当我尾随 ${INSTRUMENTS_LOG_FILE} 时,我可以看到日志的最后一部分延迟到模拟器上的应用程序关闭。即当仪器退出时,日志才被放入日志文件中。

我想强制重定向的缓冲区大小为 0,即立即登录文件。

我该怎么做?

谢谢

OSX 有unbuffer还是stdbuf


这是我的Linux系统上/usr/bin/unbuffer的内容。

#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl 
exec tclsh "$0" ${1+"$@"}
package require Expect

# -*- tcl -*-
# Description: unbuffer stdout of a program
# Author: Don Libes, NIST
if {[string compare [lindex $argv 0] "-p"] == 0} {
    # pipeline
    set stty_init "-echo"
    eval [list spawn -noecho] [lrange $argv 1 end]
    close_on_eof -i $user_spawn_id 0
    interact {
    eof {
        # flush remaining output from child
        expect -timeout 1 -re .+
        return
    }
    }
} else {
    set stty_init "-opost"
    set timeout -1
    eval [list spawn -noecho] $argv
    expect
    exit [lindex [wait] 3]
}

最新更新