jdinunzio
jdinunzio

Reputation: 1608

exec.Run and argv problem

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.

Upvotes: 3

Views: 736

Answers (1)

marketer
marketer

Reputation: 43677

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

Upvotes: 4

Related Questions