child.cpp 902 Bytes
Newer Older
Tijana Vukovic's avatar
Tijana Vukovic committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <string>
#include <vector>

#include <Windows.h>

#include <migraphx/errors.hpp>

int main()
{
    std::vector<char> result;
    HANDLE std_in  = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE);

    if(std_in == INVALID_HANDLE_VALUE)
        MIGRAPHX_THROW("STDIN invalid handle (" + std::to_string(GetLastError()) + ")");
    constexpr std::size_t BUFFER_SIZE = 1024;
    DWORD bytes_read;
    TCHAR buffer[BUFFER_SIZE];
    for(;;)
    {
        BOOL status = ReadFile(std_in, buffer, BUFFER_SIZE, &bytes_read, nullptr);
        if(status == FALSE or bytes_read == 0)
            break;
        DWORD written;
        if(WriteFile(std_out, buffer, bytes_read, &written, nullptr) == FALSE)
            break;
        // result.insert(result.end(), buffer, buffer + bytes_read);
    }
    // std::cout << result.data();
    return 0;
}