Exec.Run and argv problem

I want to create an exec.Cmd array and connect them together to make a squid authenticator. It works when the commands in the file have no arguments. With arguments, he reads only EOF . I checked the argv array and its contents are fine.

Relevant piece of code:

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? Thank.

PS: If this helps, the full source of the program is on github .

+3
source share
1 answer

Args should also include arg0. Try exec.Run (parts [0], parts)

I opened a question about how this is confusing, but they claim it works as intended: http://code.google.com/p/go/issues/detail?id=428

+4
source

Source: https://habr.com/ru/post/1730233/


All Articles