-
-
Save rking/ce052ba296e23b1e277f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## Swipe stdout from another program by pid (using strace -p) | |
# Test by running | |
# echo $$; while sleep .5; do echo '"\"; system("echo egads"); \""'; done | |
# (observe the pid that comes out at the start) | |
pid = ARGV[0].to_s or fail "Need a pid to trace." | |
cmd = ['strace', '-p', pid, '-e', 'write', '-s', '999999', :err=>[:child, :out]] | |
IO.popen cmd do |io| | |
io.each_line do |line| | |
line.sub /^write\(1, "(.+)", \d+\)/ do | |
puts eval %{"#{$1}"} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment