Thanks for the answers ! I will check reptyr out. I have looked at trying 
to rewrite https://github.com/jerome-pouiller/reredirect which seems to be 
similar to what I am looking for. I want this because I would like to write 
a application to catch stdout of another process for logging purposes. From 
the applications execution side I didn't want to make any changes. Just 
start the application that outputs to stdout and then start my application 
to capture the output. I have multiple applications that have a lot of 
command line flags and didn't want to have to worry about executing them 
threw os.exec. I thought it would be nice to be able to pass a PID and 
redirect any stdout to my application. After looking into it more I do 
understand that its a odd task haha. 

On Friday, July 1, 2016 at 2:34:50 PM UTC-4, Konstantin Khomoutov wrote:
>
> On Fri, 1 Jul 2016 10:28:59 -0700 (PDT) 
> ethanl...@gmail.com <javascript:> wrote: 
>
> > I am starting to look into intercepting a running processes output. I 
> > know how to do this manually by look at /proc/$PID/fd/1 or by using 
> > gdb etc. I do not want to use os.exec and then join the child 
> > processes output with the parent. I want to start Process A and 
> > capture the output of A in Process B.  Does anyone have any advice on 
> > where to start or an opinion on why I should just use os.exec ? Any 
> > advice/help would be great ! 
>
> I'm afraid that this would be inherently kludgy. 
>
> As C Banning hinted, the standard output (and input) streams of a 
> process are _already_ connected to somewhere when a process starts up 
> by an operating system.  They can be opened to a file or something 
> resembling a file -- such as an OS pipe or a socket. 
>
> Hence what you want is "retargetting" an already opened and existing 
> file descriptor of a foreign process, which is not something available 
> in the "standard" set of system calls. 
>
> If, for some reason, you still dearly need to do something like this, 
> try looking at reptyr [1] which plays dirty unportable tricks with 
> ptrace(). 
>
> In any case it would be interesting to hear _why_ would you need that. 
>
> 1. https://github.com/nelhage/reptyr 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to