File: driver.cc

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (52 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bobcat/pipe>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
#include <string>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
try
{
    Pipe p;                         // construct a pipe

    cout << "Read file descriptor: " << p.readFd() << endl;
    cout << "Write file descriptor: " << p.writeFd() << endl;

    int pid = fork();

    if (pid == -1)
        return 1;

    if (!pid)                       //child
    {
        p.readFrom(STDIN_FILENO);   // read what goes into the pipe from cin

        string s;

        getline(cin, s);

        cout << "CHILD: Got `" << s << "'" << endl;

        getline(cin, s);

        cout << "CHILD: Got `" << s << "'" << endl;

        return 0;
    }

    p.writtenBy(STDOUT_FILENO);      // write to the pipe via cout

    cout << "first line" << endl;
    cout << "second line" << endl;

    waitpid(pid, 0, 0);
}
catch (exception const &err)
{
    cout << err.what() << endl;
    return 1;
}