I'm issuing the following commands to extract symbol information from an elf file:
p = subprocess.Popen(["gdb", "-q", "my.elf", "-ex", symbol, "-ex", "q"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = p.stdout.peek().decode('utf-8').splitlines()
If I run the code then the only thing I get back from the command is: 'Reading symbols from /home/user/my.elf...done.'
If I step through the code with a debugger or put in a time.sleep(1) call between the Popen and the peek() commands, then I get a list with the structure elements as members. So it looks like Popen doesn't wait for gdb to finish processing the command.
Can someone explain why this is the case and offer a workaround? Putting in a 1 second sleep between each call is going to take way too long for something that contains hundreds if not thousands of symbols. Thanks.