exec.Run和argv问题

huangapple go评论90阅读模式
英文:

exec.Run and argv problem

问题

我想创建一个 exec.Cmd 数组,并将它们连接在一起以创建一个 squid 认证器。当 file 中的命令没有参数时,它可以正常工作。但是当有参数时,它只会读取 EOF。我已经检查了 argv 数组,它的内容是正确的。

代码的相关部分如下:

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

    // 初始化配置文件中的命令
    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]
}

有什么想法吗?
谢谢。

附注: 如果有帮助的话,完整的程序源代码在 github 上。

英文:

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.

答案1

得分: 4

参数需要包括arg0。尝试执行exec.Run(parts[0], parts)。

我已经提出了一个关于这个问题的问题,但他们声称这是按预期工作的:
http://code.google.com/p/go/issues/detail?id=428

英文:

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

huangapple
  • 本文由 发表于 2010年1月27日 23:37:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/2148190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定