【问题标题】:ForkExec and Su problem in GoGo 中的 ForkExec 和 Su 问题
【发布时间】:2011-04-25 04:23:24
【问题描述】:

我写了一个在 Go 中使用 ForkExec 的程序。

command := "/bin/su -c '/bin/ls -lh / >/tmp/sC0X3kASz7' joe"

pid, err := os.ForkExec(command, []string{}, os.Environ(), "", []*os.File{nil, cmd.Stdout, cmd.Stderr})

如果您在 shell 上执行该命令并执行cat /tmp/sC0X3kASz7,您将看到列出的文件。

然而,上面的 ForkExec 只创建文件,并没有在其中写入任何内容。知道为什么会这样吗?

go 是 root。

编辑:command := "/bin/ls -lh / >/tmp/sC0X3kASz7" 也不起作用,只是尝试过。它甚至不创建 /tmp 文件。

edit2 : command := "/bin/bash /tmp/command.txt" 我把上面的命令放在这个 txt 文件中,再次从 shell 执行,文件被创建,从 ForkExec - nope :(

edit3 : 解决方案在这里http://code.google.com/p/go/issues/detail?id=428

【问题讨论】:

    标签: go


    【解决方案1】:

    用户 joe 是否可能出于某种原因无法列出 / ? stderr 似乎无处可去。

    【讨论】:

    • 我也在尝试使用 root,只是注意到,即使没有 su,它也不会创建 /tmp 文件
    猜你喜欢
    • 2011-11-25
    • 1970-01-01
    • 2010-10-30
    • 2018-06-28
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    相关资源
    最近更新 更多