| reopen |
(Stream replacement, Stream original) |
yoix.io |
| |
Closes
original,
and then attaches to it the stream named by
replacement
with access determined by the replacement stream.
reopen
returns
original,
or
NULL
if the re-open failed.
In either case, the original
stream
is flushed and closed.
| |
| Example: |
The following script redirects the standard output so that it writes to
a
StringStream.
A thread monitors additions to the stream and writes them to standard error.
After a couple of test writes to standard output, the main thread kills
the monitor thread, closes the string stream and writes its contents on
standard error.
Note that the thread is not a necessary component, but only included to
make the example a little more interesting.
import yoix.io.*;
import yoix.stdio.*;
import yoix.string.*;
import yoix.thread.*;
StringStream ss = {
int mode = WRITE;
int open = TRUE;
};
Thread ethr = {
run() {
String line;
reopen(ss, stdout);
int cnt = stdout.size;
while (1) {
if (cnt != stdout.size) {
line = ss.name;
fprintf(stderr,
"Stdout got: %s", substring(line,cnt));
cnt = line@length;
} else sleep(1);
}
}
};
ethr.run();
fprintf(stdout,"line 1\n");
sleep(2);
fprintf(stdout,"line 2\n");
sleep(2);
fprintf(stdout,"line 3\n");
sleep(2);
ethr.alive = 0;
ss.open = FALSE;
fprintf(stderr, "StringStream contains:\n%s", ss.name);
Standard error would contain the following:
Stdout got: line 1
Stdout got: line 2
Stdout got: line 3
StringStream contains:
line 1
line 2
line 3
| | |
| Return: |
Stream
| | |
| See Also: |
access,
close,
fclose,
fflush,
fopen,
freopen,
open,
stat,
unlink
|
|
Yoix is a registered trademark of AT&T Inc.
|