<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
At 25.11.2010 19:57, Jonas Maebe wrote:
<blockquote
cite="mid:82DDBBCF-885D-4DE4-9BCE-32125C4120B3@elis.ugent.be"
type="cite">
<pre wrap="">On 25 Nov 2010, at 13:21, Jonas Maebe wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 25 Nov 2010, at 12:24, Anton Kavalenka wrote:
</pre>
<blockquote type="cite">
<pre wrap="">What I have to do to properly initialize these defaults for new threads AFTER capturing StdOut?
</pre>
</blockquote>
<pre wrap="">Store a copy of your stdout in a global variable, and after creating a new thread
close(stdout);
stdout:=myglobalstdout;
(and maybe the same for "output").
</pre>
</blockquote>
<pre wrap="">Actually, that won't work because the different threads will then work on a common buffer but with distinct pointers into it. A better solution is probably to do this in the intialisation code of each thread instead:
{$ifdef unix}
fpclose(ttextrec(stdout).handle);
{$elsif defined(MSWINDOWS)}
{ this is a copy of do_close() from the rtl, I don't know whether
a new handle from a thread can actually have any of these values }
if (handle <> StdInputHandle) and
(handle <> StdOutputHandle) and
(handle <> StdErrorHandle) then
CloseHandle(ttextrec(stdout).handle);
{$else}
{$error Add support for this platform}
{$endif}
ttextrec(stdout).handle:=myglobalstdouthandle;
Jonas_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated"
href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext"
href="http://lists.freepascal.org/mailman/listinfo/fpc-devel">http://lists.freepascal.org/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<font face="Helvetica, Arial, sans-serif">That's unsuitable. I have
lots of modules and lost of threads. Many modules built with C++
runtime, others with C.<br>
Output goes from many places and many threads.<br>
The task is to do inside process what the UNIX tee command does outside.<br>
<br>
regards,<br>
Anton<br>
<br>
<br>
<br>
<br>
<br>
</font>
</body>
</html>