0

This works:

(make-process :name "test"
      :command (list "bash" "-c"
     (concat "echo hello stdout!; "
     "echo hello stderr! >&2; "
     "exit 20"))
      :buffer (generate-new-buffer "*stdout*")
      ;;:stderr (generate-new-buffer "*stderr*")
              ;;:noquery nil
              )

but, I want this code to work:

(make-process :name "test"
          :command (list "bash" "-c"
                 (concat "echo hello stdout!; "
                     "echo hello stderr! >&2; "
                                     "echo enter your name; "
                                     "read name; "
                                     "echo enterted name was $name; "
                     "exit 0"))
          :buffer (generate-new-buffer "*stdout*")
          ;;:stderr (generate-new-buffer "*stderr*")
              ;;:noquery nil
              )

In other words, when the process sits and waits for user input, the end user should be prompted in the emacs echo area. (I think tramp does something like this when it encounters a password prompt)

not part of this SO question, but eventually I would like to integrated the solution in to (defun org-babel-sh-evaluate (session body &optional params stdin cmdline) of https://code.orgmode.org/bzg/org-mode/src/master/lisp/ob-shell.el

1

TRAMP does a pretty ugly hack to detect a network process prompting for input, it uses regex matching to detect a printed prompt, then asks for user input using tramp-read-passwd. This will obviously not work with your example as there's no matchable prompt to look for.

I doubt there's a generic solution to this considering how reading user input works in a terminal application. User input is read in whenever requested from standard input, with your keyboard (or any input redirection) hooked up to it. Prompts are printed to signal the user they're expected to type in something. If you run a subprocess from Emacs there is no way to tell when user input is read in from the application, other than by trying to look for hints intended for humans (such as the printed prompt).

  • when a (bash) process waiting for user input, it's cpu-use metric must be 0%, can we use something silly like that ... – american-ninja-warrior Jan 16 at 18:22
  • This is impossible to distinguish from intentional sleep calls... – wasamasa Jan 17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.