Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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

share|improve this answer

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'
share|improve this answer

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.
share|improve this answer
    
the motivation to reanswer this question came from news.ycombinator.com/item?id=2110636 and 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 6:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.