2

I am running instruments on mac, and I want to redirect the output to a file.

The following is the command I am using:

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

Now, when I tail the ${INSTRUMENTS_LOG_FILE}, I can see that the last part of logs is delayed till the application on the simulator closes. i.e when instruments exit, only then the logs are being put in the log file.

I want to force the redirect to have a buffer size of 0, i.e immediately log into the file.

How can I do this?

Thanks

Neeraj
  • 8,408
  • 8
  • 41
  • 69
  • This is discussed in another question about output buffering here: http://stackoverflow.com/questions/3332045/bash-force-execd-process-to-have-unbuffered-stdout – Tim B Dec 17 '12 at 15:35

1 Answers1

0

Does OSX have unbuffer or stdbuf?


Here is the contents of /usr/bin/unbuffer on my Linux system.

#!/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]
}
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • No unfortunately both of those aren't available.Expect is available but I am not sure how that would be used. – Neeraj Dec 17 '12 at 14:36
  • unbuffer is often found the tcl programming language package (maybe others too). You may already have it, but doing `find / -name 'unbuffer*' may take a while. Or can definitely install it. Good luck. – shellter Dec 17 '12 at 15:12
  • Expect has an unbuffer script in it. – Tim B Dec 17 '12 at 15:32