From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-12T07:16:51+09:00 Subject: Re: RCR for child execution On Sun, 11 May 2003 19:12:17 +0900, Brian Candler wrote: > On Sun, May 11, 2003 at 09:29:43AM +0900, Simon Strandgaard wrote: >> stdout = fdopen(new_stdout, "a"); // BOOM! >> stderr = fdopen(new_stderr, "a"); // BOOM! > > The particular BOOM I get is: > > main.cpp:40: non-lvalue in assignment > main.cpp:41: non-lvalue in assignment > > That's because stdout is not a variable: on my FreeBSD box it is defined as All my boxes run FreeBSD5.0 :-) I don't get any warnings/errors. > extern FILE __sF[]; > ... > #define stdout (&__sF[1]) > > (so it's not a pointer variable which can be reassigned, it is a pointer to > a static piece of storage) > > To reopen stdout you need either 'freopen' (at the stdio.h layer) or 'dup2' > (at the Unix API layer). from man freopen FILE * freopen(const char *path, const char *mode, FILE *stream); I don't know what "path" I should initialize freopen with, therefore I use dup2 + fdopen. int new_stdout = dup2(bak_stdout, 1); stdout = fdopen(new_stdout, "a"); >> Well, there is no thread to flush the pipe.. but this is not important >> here! What is important is that system('ls a.c xx')'s output goes to >> stdout/stderr, is mixed up with C's output. > > Yes, of course it is. > > If you want the child to have a different stdout/stderr than yours, then > what you need to do is: > - fork > - (in child) reopen stdout/stderr > - (in child) exec > - (in parent) wait for child to finish I know im terrible expressing myself in english, so be gentle with me :-) Separation of ruby stdout/stderr from C/C++ stdout/stderr is what I want. I run Ruby in the same thread as C++ (ruby embedded into C++). This separation is working fine, as long as I don't use system or backquote. Using system or backquote, then it goes BOOM. The problem as I see it is localized in Rubys code - not mine! Ruby spawns a child which inherits stdout/stderr. This child should instead inherit rb_stdout/rb_stderr instead!!! Can this issue be fixed on Ruby ??? > It sounds to me like you are actually asking for changes to Unix, but I > can't see exactly what. I have no problems with Unix.. I think you underestimate me because of my broken english... I have been programming my hole life.. I just recently started to poke around with unix-pipes. I am very familiar with sockets so no big difference here. Thanks for putting so much effort in it anyway :-) -- Simon Strandgaard