I am writing an elisp function that sends a command to an existing eshell buffer, waits for the command to finish, and send another command. For example, I would like to send:
python
2+3
So far I have tried the following, unsuccessfully:
1.Getting the eshell process to use process-send-string
and accept-process-output
:
(process-send-string eshell-proc "python")
(accept-process-output eshell-proc 100)
But I have been unable to get the eshell process. (get-buffer-process (current-buffer))
returns nil
when the current buffer is eshell.
2.Inserting the command in the buffer, using (eshell-send-input)
, and sleeping for a bit before sending the next command:
(progn
(insert "python")
(eshell-send-input)
(sleep-for 1)
(insert "2+3")
(eshell-send-input))
The problem with this approach is that "2+3" gets sent before the python subprocess has been launched. This happens regardless of the amount of time for which I sleep. It seems that sleeping freezes all of emacs' subprocesses?
3.Using eshell-gather-process-output
:
If I use either:
(eshell-gather-process-output "/usr/bin/python" nil)
or
(eshell-gather-process-output "/usr/bin/python" (list "somearg"))
I get Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
But if I use:
(eshell-gather-process-output "/usr/bin/python" (vector "somearg"))
I get Debugger entered--Lisp error: (wrong-type-argument listp ["somearg"])
So I am really confused as to what type of argument this command expects. I haven't been able to find a single example of usage of this command.
Why does something so simple become so complicated? Thanks for any inputs