I normally redirect STDOUT to another program using:
python -c 'print("HelloWorld")' | ./myprog
I know that I can supply the contents of a file as STDIN for a debugged program in GDB:
(gdb) run myprog < input.txt
However, how can I do something like:
(gdb) run mypprog < python -c 'print("HelloWorld")'
without first having to create a file with the output of python -c '...'
?
One way is to attach gdb to your already-running process. Find its pid with ps
or top
. Let's say that it's 37. Then run
(gdb) attach 37
That probably won't work for your case with very short run time though. Another approach is to use a fifo .
mkfifo fifo
python -c 'print("Hello World")' > fifo &
gdb myprog
run < fifo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.