use dup2 to redirect io