I am writing some C code that involves the use of pipes. To make a child process use my pipe instead of STDOUT for output, I used the following lines:

```
    close(STDOUT);
    dup2(leftup[1], STDOUT);

```

However, it seems to go into some sort of infinite loop or hang on those lines. When I get rid of `close`, it hangs on `dup2`. 

Curiously, the same idea works in the immediately preceding line for STDIN:

```
close(STDIN);
dup2(leftdown[0], STDIN);

```

What could be causing this behavior?

Edit: Just to be clear...

```
#define STDIN   0
#define STDOUT  1

```

Edit 2: Here is a stripped-down example:

```
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>

#define STDIN   0
#define STDOUT  1

main(){
    pid_t child1 = 0;
    int leftdown[2];
    if (pipe(leftdown) != 0)
        printf("ERROR");
    int leftup[2];
    if (pipe(leftup) != 0)
        printf("ERROR");

    printf("MADE PIPES");

    child1 = fork();
    if (child1 == 0){
        close(STDOUT);
        printf("TEST 1");
        dup2(leftup[1], STDOUT);
        printf("TEST 2");
        exit(0);
    }
    return(0);  
}

```

The `"TEST 1"` line is never reached. The only output is `"MADE PIPES"`.