Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exec.Run and argv problem

Tags:

go

I want to create an array of exec.Cmd and pipe them together to make an squid authenticator. It works when the commands in file have no arguments. With arguments, it only reads EOF. I've checked the argv array and its content is ok.

The relevant portion of the code is:

func initCmd(file *os.File) []* exec.Cmd {
    var cmd     [MAX_PROC]* exec.Cmd;
    var e       os.Error

    // Initialize the commands in the config file
    environ := os.Environ();
    var i int
    for i=0; i < MAX_PROC; i++ {
        line := getLine(file)
        if line == "" { break }
        parts := strings.Fields(line)
        cmd[i], e = exec.Run(parts[0], parts[1:], environ, 
                             exec.Pipe, exec.Pipe, exec.Pipe)
        exitOnError(&e)
    }
    return cmd[0:i]
}

Any ideas? Thanks.

PS: If it helps, the complete program source is at github.

like image 274
jdinunzio Avatar asked Mar 09 '26 02:03

jdinunzio


1 Answers

The args need to include arg0 also. Try exec.Run(parts[0], parts)

I opened an issue about how this is confusing, but they claim it's working as intended: http://code.google.com/p/go/issues/detail?id=428

like image 58
marketer Avatar answered Mar 10 '26 14:03

marketer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!