I have created a comint mode for using mongo. The mode works fine in the buffer, and now I am trying to use it programmatically where I need to get the output from commands.
Getting input to the process works fine. Getting output from the process though has remained tricky. What I want is to send a cmd to the mongo process, and have the function that sent the command return the output.
I have setup a filter function where I save the output into a variable:
(defun mongo-output-filter (output) "Hook function for handling process output." (setq mongo-output output))
I setup a function to take a command like this:
(defun ts (cmd) (comint-simple-send (get-buffer-process "*Mongo*") cmd) mongo-output)
The trouble is that sometimes it works, and sometimes it doesn't. What does work is I see the output in the Mongo buffer, but it isn't always returned by the function.
I tried adding (accept-process-output (get-buffer-process "Mongo")), but that does not always give me the output. Sometimes it does, and sometimes I just get a prompt. It doesn't seem to matter if I use any optional arguments.
Is this the right way to go about this? None of the other questions on SO seem to answer this question.