// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <cstdio>
#include <iostream>

#include <fcntl.h>
#include <io.h>

using namespace std;

int main()
{
    int oldstdout = _dup(_fileno(stdout));
    int pipehandles[2];
    _pipe(pipehandles,20480,_O_BINARY);
    _dup2(pipehandles[1],_fileno(stdout));
    printf("Test af C IO\n");
    cout << "Test af C++ IO" << endl;
    _dup2(oldstdout,_fileno(stdout));
    char buf[20480];
    int n = _read(pipehandles[0],buf,sizeof(buf));
    printf("%s",buf);
    return 0;
}
