英文:
How do you debug a Go binary that takes input file redirection and output file redirection?
问题
我有一个名为"runme"的Go二进制文件,可以成功运行,命令如下:
./runme encrypt --password=password < plaintext.txt > encrypted.txt
它成功读取名为"plaintext.txt"的文件,并输出一个名为"encrypted.txt"的加密文件。
现在我想使用Go的dlv调试器来调试它,命令如下:
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
在调试器中似乎有一个看起来很简单的事情我做不到。我可能做错了什么?
英文:
I have a Go binary file called "runme" that successfully runs like so:
./runme encrypt --password=password < plaintext.txt > encrypted.txt
It successfully reads in a file called "plaintext.txt" and outputs an encrypted file called "encrypted.txt".
Now I would like to use the dlv debugger for Go to debug it like so:
dlv exec ./runme -- encrypt -password=password < plaintext.txt > encrypted.txt
However I get the following error message from the dlv debugger:
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
So I try again slightly differently:
dlv exec -r ./runme -- encrypt -password=password < plaintext.txt > encrypted.txt
But I get the exact same error message shown above. Then I try the following:
dlv exec --allow-non-terminal-interactive=true ./runme -- encrypt -password=password < plaintext.txt > encrypted.txt
This time I get a different error message:
Command failed: command not available
What seems like a simple thing I am not able to do in the debugger. What could I be doing wrong?
答案1
得分: 3
通过 @tkausl 和 @gopher 的帮助,我成功解决了问题。
解决方案如下:
dlv exec -r stdin:plaintext.txt -r stdout:encrypted.txt ./runme -- encrypt -password=password
英文:
With help from @tkausl and @gopher I was able to figure it out.
Solution is:
dlv exec -r stdin:plaintext.txt -r stdout:encrypted.txt ./runme -- encrypt -password=password
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论