Reputation: 4235
I am using python and invoking sub process and reading out put line by line and it is working fine as shown below.
process = subprocess.Popen(['jdebug', 'File.tgz'],
stdout=subprocess.PIPE,
universal_newlines=True)
while True:
output = process.stdout.readline()
print(output.strip())
return_code = process.poll()
print( return_code)
if "lastdata" in str(output): <- How to send 'bt' and 'quit' command at this point and read the response back.
process.communicate('bt')
process.communicate('quit')
if return_code is not None:
# Process has finished, read rest of the output
for output in process.stdout.readlines():
print(output.strip())
break
I want to issue 'bt' and "quit" command to the "jdebug" process When the above condition is true to quit the process. Since jdebug process don't return back the control and python program needs to explicitly issue 'Quit' command to get the control back.
Wondering how to do that?
I am sending this value: process.stdin.write('bt\n') process.stdin.write('quit\n')
Upvotes: 3
Views: 275
Reputation: 682
# write on the stdin out of your process
subprocess.stdin.write('QUIT')
Upvotes: 6