3

I'm having a php-cli script that is running (detached) in the background.

Is there a way to attach to it's Stdout/Stderr in order to see the output of the application?

akira
  • 61,009
  • 17
  • 135
  • 165
ufk
  • 901
  • 6
  • 23
  • 38

3 Answers3

3

I like using strace it's abit less intimidating than GDB.

strace -s 100000 -e write=1  -e trace=write -p $PID 2>&1 | \
   sed 's/^write(1, //;t;d'
akira
  • 61,009
  • 17
  • 135
  • 165
3

You can probably do this with gdb. I wrote about the process in an answer to a vaguely-related question.

quack quixote
  • 42,186
  • 14
  • 105
  • 129
1

dupx is the complete solution which implements what @quack is refering to:

Dupx is a simple utility to remap files of an already running program. Shells like Bash allow easy input/output/error redirection at the time the program is started using >, /tmp/stdout will redirect output of echo to /tmp/stdout. Standard shells however do not provide the capability of remapping (redirecting) of output (or input, or error) for an already started process. Dupx tries to address this problem by using dup(2) system call from inside gdb(1). Dupx is currently implemented as a simple shell wrapper around a gdb script.
akira
  • 61,009
  • 17
  • 135
  • 165
  • the motivation to reanswer this question came from http://news.ycombinator.com/item?id=2110636 and https://gist.github.com/782263 and no good results while searching superuser. i found the vaguely-related posts on SU but things could be simpler. – akira Jan 17 '11 at 06:48