github.com/atrn/dcc@v0.0.0-20220806184050-4470d2553272/exec.go (about)

     1  // dcc - dependency-driven C/C++ compiler front end
     2  //
     3  // Copyright © A.Newman 2015.
     4  //
     5  // This source code is released under version 2 of the  GNU Public License.
     6  // See the file LICENSE for details.
     7  //
     8  
     9  package main
    10  
    11  import (
    12  	"io"
    13  	"log"
    14  	"os"
    15  	"os/exec"
    16  	"strings"
    17  )
    18  
    19  // Exec executes a command with the supplied arguments and directs its
    20  // standard error output stream to the supplied io.Writer. The
    21  // command's standard input is connected to /dev/null and the output
    22  // stream connected to our standard output.
    23  //
    24  func Exec(path string, args []string, stderr io.Writer) error {
    25  	if Debug {
    26  		log.Println("EXEC:", path, strings.Join(args, " "))
    27  	}
    28  
    29  	cmd := exec.Command(path, args...)
    30  	cmd.Stdin, cmd.Stdout, cmd.Stderr = nil, os.Stdout, stderr
    31  	return cmd.Run()
    32  }