英文:
ForkExec and Su problem in Go
问题
我写了一个在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文件。
编辑2:command := "/bin/bash /tmp/command.txt"
,我将上面的命令放在这个txt文件中,再次从shell执行,文件被创建了,但从ForkExec中没有(没有创建)。
编辑3:解决方案在这里http://code.google.com/p/go/issues/detail?id=428
英文:
I wrote a program that uses ForkExec in Go.
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})
if you execute that command on your shell, and do cat /tmp/sC0X3kASz7
you will see your files listed.
however, ForkExec above only creates the file and writes nothing in it. Any idea why that'd happen ?
go is root.
edit : command := "/bin/ls -lh / >/tmp/sC0X3kASz7"
didn't work either, just tried. it doesn't even create the /tmp file.
edit2 : command := "/bin/bash /tmp/command.txt"
and i put the above command inside this txt file, again, execute from shell, file is created, from ForkExec - nope
edit3 : solution is here http://code.google.com/p/go/issues/detail?id=428
答案1
得分: 1
用户joe无法列出/的可能性有吗?标准错误似乎没有任何输出。
英文:
Is it possible that user joe can't list / for some reason? stderr appears to be going nowhere.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论