【问题标题】:Set the size of stdout buffer in shell script on mac osx在 mac osx 上的 shell 脚本中设置标准输出缓冲区的大小
【发布时间】:2023-06-28 12:33:01
【问题描述】:

我在 mac 上运行仪器,我想将输出重定向到一个文件。

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

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

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

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

我该怎么做?

谢谢

【问题讨论】:

标签: macos shell stdout instruments


【解决方案1】:

OSX 有 unbufferstdbuf 吗?


这是我的 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]
}

【讨论】:

  • 不,不幸的是,这两个都不可用。Expect 可用,但我不确定如何使用。
  • unbuffer 经常出现在 tcl 编程语言包中(也可能是其他语言包)。您可能已经拥有它,但执行 `find / -name 'unbuffer*' 可能需要一段时间。或者绝对可以安装它。祝你好运。
  • 期望里面有一个 unbuffer 脚本。
最近更新 更多