tags:

views:

119

answers:

1

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.

+3  A: 

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

marketer
Now that's ugly API design. With keyword arguments they could have aped the way nicer subprocess: http://docs.python.org/library/subprocess.html#subprocess.Popen
Tobu
It's ugly because they more or less copied the behavior of the standard C library functionality, which is also why they claim it's working as intended. In fact, they're probably just calling one of the many variants of the C function "exec" under the hood.
Russell Newquist