/tmp/sC0X3kASz7' joe" pid, err :=-6ren">
gpt4 book ai didi

go - Go中的ForkExec和Su问题

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:01 25 4
gpt4 key购买 nike

我写了一个在 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 是根。

edit : command := "/bin/ls -lh/>/tmp/sC0X3kASz7" 也没有用,只是试过了。它甚至不创建/tmp 文件。

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

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

最佳答案

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

关于go - Go中的ForkExec和Su问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3929607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com