osx capture output of running process

Developer from somewhere

Problem: want to capture output of an already running process

Solution: found here

capture() {
    sudo dtrace -p "$1" -qn '
        syscall::write*:entry
        /pid == $target && arg0 == 1/ {
            printf("%s", copyinstr(arg1, arg2));
        }
    '
}

after, run:

  • save above code in capture.sh
  • source capture.sh
  • capture PID