Is there a way to see the programs stdout and stderr in delve debugger for golang?

huangapple go评论75阅读模式
英文:

Is there a way to see the programs stdout and stderr in delve debugger for golang?

问题

当使用delve调试Go程序时,我想要能够看到stdout和stderr的输出。这个有可能吗?我该如何做到这一点?

英文:

I'd like to be able to see the stdout and stderr when using delve to debug go programs. Is this possible? How would I do this?

答案1

得分: 1

你不需要做任何事情。

Delve默认将stdout和stderr打印到其控制台。我在MacOS ElCapitan上尝试过这个,使用的是Delve版本0.11.0-alpha。

在你的GOPATH的正确子目录中有一个main.go文件:

package main

import "fmt"
import "os"

func main() {
    fmt.Fprintf(os.Stderr, "Writing something to stderr\n")
    fmt.Fprintf(os.Stdout, "Writing something to stdout\n")
}

然后在与main.go相同的目录中运行Delve:

$ dlv debug
Type 'help' for list of commands.
(dlv) restart
Process restarted with PID 70964
(dlv) c
Writing something to stderr
Writing something to stdout
Process 70964 has exited with status 0
(dlv)
英文:

You do not need to do anything.

Delve by default prints the stdout and stderr to its console.
I have tried this in MacOS ElCapitan delve version 0.11.0-alpha

Have a main.go in the right subdir in your GOPATH

package main

import "fmt"
import "os"

func main() {
	fmt.Fprintf(os.Stderr, "Writing something to stderr\n")
	fmt.Fprintf(os.Stdout, "Writing something to stdout\n")
}

Then run the delve in the same dir as the main.go

$ dlv debug
Type 'help' for list of commands.
(dlv) restart
Process restarted with PID 70964
(dlv) c
Writing something to stderr
Writing something to stdout
Process 70964 has exited with status 0
(dlv)

huangapple
  • 本文由 发表于 2015年11月19日 03:58:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/33789220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定