【发布时间】: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