使用GDB模拟回声输入

imr*_*mre 2 terminal stdin gdb stream

所以我试图调试一个程序,要求用户通过终端输入一些文本:

$ echo 'here is the text' | ./program
Run Code Online (Sandbox Code Playgroud)

如何在GDB中模拟输入?

Emp*_*ian 5

您可以使用重定向的输入运行程序:

echo 'here is the text' > intput.txt
gdb ./program
(gdb) run < intput.txt
Run Code Online (Sandbox Code Playgroud)