英文:
What is the difference between os.Stdout and syscall.Stdout?
问题
我一直在尝试使用ForkExec()函数,但无法使其正常工作,syscall.Stdout和os.Stdout之间有什么区别吗?
以下是我尝试运行的代码示例:
command := "/usr/bin/echo"
args := []string{"Hello there."}
attr := new(syscall.ProcAttr)
attr.Env = os.Environ()
attr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)}
pid , err := syscall.ForkExec(command, args, attr)
if err != nil {
log.Fatal(err)
}
fmt.Println(pid)
输出没有显示在屏幕上。
非常感谢您提前的帮助。
英文:
I have been trying to work ForkExec() and I am not able to get this one work, is there a difference between syscall.Stdout and os.Stdout?
Here is a small example of the code I am trying to run.
command := "/usr/bin/echo"
args := []string{"Hello there."}
attr := new(syscall.ProcAttr)
attr.Env = os.Environ()
attr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)}
pid , err := syscall.ForkExec(command, args, attr)
if err != nil {
log.Fatal(err)
}
fmt.Println(pid)
The output is not showing up on the screen.
Thanks a lot for your help in advance.
答案1
得分: 5
os.Stdout
是一个 *os.File
。它与需要 io.Writer
或类似接口的 Go 函数一起使用。syscall.Stdout
是一个整数常量。它是标准输出的文件描述符号,对于低级系统调用非常有用。
syscall.ForkExec
确实需要文件描述符号... 但不清楚为什么你要使用它,而不是更直接的 os/exec.Cmd
。
英文:
os.Stdout
is a *os.File
. It works with go functions that want an io.Writer
or similar interfaces. syscall.Stdout
is an integer constant. It's the file descriptor number of stdout, which is useful for low-level syscalls.
syscall.ForkExec
does indeed want file descriptor numbers... but it's unclear why you're using that instead of os/exec.Cmd
which is much more straightforward.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论