From: Brian Candler Date: 2003-05-14T08:08:59+09:00 Subject: Re: RCR for child execution On Tue, May 13, 2003 at 11:33:10PM +0900, Simon Strandgaard wrote: > Kernel#fork does spawn a child.. changes to Rubys Core is necessary. > unix-fork inherit stdin/stdout/stderr from parent to the child process. > I want Rubys Kernel#fork to inherit rb_stdin/rb_stdout/rb_stderr from the > parent to the child process. > But hey.. unix-fork() does not take any arguments. Is this possible? > My guess - Yes this should be possible. Here is some pseudo code. > > void Kernel#fork() { > backup_stdout = stdout; /* what i want */ > stdout = rb_stdout; /* what i want */ > pid = fork(); > if(pid == 0) > stdout = backup_stdout; /* what i want */ > } That pseudo-code doesn't make sense: a Ruby object cannot be assigned to a FILE*, nor can it be put in the Unix file descriptor table. > This way stdout/stderr/stdin should be untouched and remain usable in the C/C++ > application. > > Does it answer the question ? No, because it cannot work. If I write s = "" $stdout = StringIO.new(s) pid = fork do exec("ls *.txt") end Process.wait(pid) how are you going to modify fork or exec so that it captures the output of 'ls' into the StringIO object created earlier? Brian.