【问题标题】:How do you debug a Go binary that takes input file redirection and output file redirection?如何调试接受输入文件重定向和输出文件重定向的 Go 二进制文件?
【发布时间】:2021-10-02 01:33:08
【问题描述】:

我有一个名为“runme”的Go 二进制文件,它可以像这样成功运行:

./runme encrypt --password=password < plaintext.txt > encrypted.txt

它成功读入一个名为“plaintext.txt”的文件,并输出一个名为“encrypted.txt”的加密文件。

现在我想使用dlv debugger for Go 来调试它:

dlv exec  ./runme -- encrypt -password=password < plaintext.txt > encrypted.txt

但是,我从 dlv 调试器收到以下错误消息:

Stdin is not a terminal, use '-r' to specify redirects for the target process or --allow-non-terminal-interactive=true if you really want to specify a redirect for Delve

所以我再次尝试稍有不同:

dlv exec -r ./runme -- encrypt -password=password < plaintext.txt > encrypted.txt

但我得到了与上面显示的完全相同的错误消息。然后我尝试以下方法:

dlv exec --allow-non-terminal-interactive=true  ./runme -- encrypt -password=password < plaintext.txt > encrypted.txt

这次我收到了不同的错误信息:

Command failed: command not available

我在调试器中无法完成的看似简单的事情。我可能做错了什么?

【问题讨论】:

  • So I try again slightly differently: 真的吗? ...您是否阅读过有关如何使用 -r 的文档?
  • 使用 -r 标志。 dlv help redirect
  • 我试过 dlv exec -r [stdin] plaintext.txt -r [stdout] encrypted.txt ./runme -- encrypt -password=password 但它给了我错误“重定向错误:标准输入重定向两次”

标签: go stdout stdin delve


【解决方案1】:

在@tkausl 和@gopher 的帮助下,我得以解决。

解决办法是:

dlv exec -r stdin:plaintext.txt  -r stdout:encrypted.txt ./runme -- encrypt -password=password

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多