开发者

exec.Run and argv problem

开发者 https://www.devze.com 2022-12-18 10:25 出处:网络
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

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号