Stack Overflow Asked by Ammad on November 13, 2020
I am using Jdebug system call using python and trying to automate the process of "bt" command as shown below.
It consists of two steps.
jdebug core-tarball.0.tgz
Response received:
Using '/tmp' as temporary location
jdebug version: 5.0.0
[File is compressed. This may take a moment...]
....
[Current thread is 1 (LWP 100276)]
(gdb)
As seen above (gdb) prompt is appear and now i need to pass "bt" command and to read back the response from gdb prompt.
Not sure how to send "bt" command via python or at shell script and read the response back.
I am looking to automate these two steps:
Step #1: jdebug filename
Step #2 bt
[invoke ‘bt’ on gdb prompt and read back the response lines i.e. stack_trace information] via pyton or via os.system call.
You can use Popen.communicate() for this.
import subprocess
p = subprocess.Popen(["jdebug", "core-tarball.0.tgz"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdout_data, stderr_data = p.communicate("bt")
print(stdout_data)
print(p.returncode)
Correct answer by alexisdevarennes on November 13, 2020
You can write to stdin using Popen of subprocess module:
from subprocess import Popen, PIPE
proc = Popen(['jdebug', 'core-tarball.0.tgz'], stdin=PIPE)
proc.stdin.write("btr")
Answered by user9353542 on November 13, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP