func build(gcfile string, opts []string, proFileName string, files []string, envv []string, dir string) (status syscall.WaitStatus, err os.Error) { arg := []string{gcfile, "-o", proFileName} for _, v := range opts { arg = append(arg, v) } for _, v := range files { arg = append(arg, string(v)) } fmt.Println("\t", arg) var cmd *exec.Cmd cmd, err = exec.Run(gcfile, arg[:], envv[:], dir, 0, 1, 2) if err != nil { fmt.Printf("Error, %s", err) return } defer cmd.Close() var wait *os.Waitmsg wait, err = cmd.Wait(0) if err != nil { fmt.Printf("Error, %s", err) return } status = wait.WaitStatus return }
// run runs the command argv, resolving argv[0] if necessary by searching $PATH. // It provides input on standard input to the command. func run(argv []string, input []byte) (out string, err os.Error) { if len(argv) < 1 { err = os.EINVAL goto Error } prog, ok := lookPathCache[argv[0]] if !ok { prog, err = exec.LookPath(argv[0]) if err != nil { goto Error } lookPathCache[argv[0]] = prog } // fmt.Fprintf(os.Stderr, "%v\n", argv); var cmd *exec.Cmd if len(input) == 0 { cmd, err = exec.Run(prog, argv, os.Environ(), "", exec.DevNull, exec.Pipe, exec.MergeWithStdout) if err != nil { goto Error } } else { cmd, err = exec.Run(prog, argv, os.Environ(), "", exec.Pipe, exec.Pipe, exec.MergeWithStdout) if err != nil { goto Error } go func() { cmd.Stdin.Write(input) cmd.Stdin.Close() }() } defer cmd.Close() var buf bytes.Buffer _, err = io.Copy(&buf, cmd.Stdout) out = buf.String() if err != nil { cmd.Wait(0) goto Error } w, err := cmd.Wait(0) if err != nil { goto Error } if !w.Exited() || w.ExitStatus() != 0 { err = w goto Error } return Error: err = &runError{copy(argv), err} return }
func run(argv []string, stdin, stdout, stderr int) (out string, err os.Error) { if len(argv) < 1 { err = os.EINVAL goto Error } var cmd *exec.Cmd cmd, err = exec.Run(argv[0], argv, os.Environ(), "", stdin, stdout, stderr) if err != nil { goto Error } defer cmd.Close() var buf bytes.Buffer _, err = io.Copy(&buf, cmd.Stdout) out = buf.String() if err != nil { cmd.Wait(0) goto Error } w, err := cmd.Wait(0) if err != nil { goto Error } if !w.Exited() || w.ExitStatus() != 0 { err = w goto Error } return Error: err = &runError{copy(argv), err} return }
func pack(pkfile string, target string, ofile string, envv []string, dir string) (status syscall.WaitStatus, err os.Error) { arg := []string{pkfile, "grc", target, ofile} fmt.Println("\t", arg) var cmd *exec.Cmd cmd, err = exec.Run(pkfile, arg[:], envv[:], dir, 0, 1, 2) if err != nil { fmt.Printf("Error, %s", err) return } defer cmd.Close() var wait *os.Waitmsg wait, err = cmd.Wait(0) if err != nil { fmt.Printf("Error, %s", err) return } status = wait.WaitStatus return }
/* Execute command coming from inch channel */ func execute(inch chan *command) { var c *command var cmd *exec.Cmd var err os.Error var argv0, dir string var argv []string for { c = <-inch dir = os.Getenv("PWD") switch c.cmdtype { case BUILTIN: cb := BUILTIN_COMMANDS[c.name] LAST_RETURN_VALUE = cb(c.args) case EXTERNAL: if argv0, err = exec.LookPath(c.name); err != nil { goto Error } if len(c.args) > 0 { argv = c.args } envv := os.Environ() cmd, err = exec.Run(argv0, argv, envv, dir, exec.PassThrough, exec.PassThrough, exec.PassThrough) err = cmd.Close() //TODO update LAST_RETURN_VALUE Error: if err != nil { error(err.String()) } } inch <- nil //release blockage in main loop() } }
func link(glfile string, opts []string, target string, ofile string, envv []string, dir string) (status syscall.WaitStatus, err os.Error) { arg := []string{glfile, "-o", target} for _, v := range opts { arg = append(arg, v) } arg = append(arg, ofile) fmt.Println("\t", arg) var cmd *exec.Cmd cmd, err = exec.Run(glfile, arg[:], envv[:], dir, 0, 1, 2) if err != nil { fmt.Printf("Error, %s", err) return } defer cmd.Close() var wait *os.Waitmsg wait, err = cmd.Wait(0) if err != nil { fmt.Printf("Error, %s", err) return } status = wait.WaitStatus return }