This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

[SOLVED] Running shell command from elisp

3 posts · 5725 views

Hello,

I'm writing a set of functions to automate posting html files to a webserver. I have a python script that handles authentication and attaching files and an html file. I'm having trouble calling the script because it expects input from the user, but emacs flushes EOFs to the program which results in the program quitting before it can prompt for the username/password. Is there a safe and secure way of prompting the information from the user in the minibuffer? It would be ideal if I could just have the shell command use the minibuffer for input, and output its stdout to another buffer. I just dont' know how to do this.

Thanks,

ocmsRzr

Last edited by ocmsRzr on , edited 1 time in total.

Re: Running shell command from elisp

Hi,

Didn't occur to me to also post my attempts at solving the problem.
(defun post-elog-send-post (entry-file)
  "Actually post the current buffer"
  (if (stringp entry-file)
      (setq default-directory post-elog-working-directory)
    ;(setq entry-file "~/BoostedTopPlots/log_posts/15:57_07_04_10_e_log_post.html")
    (setq command (concat post-elog-path-to-postPlots " " 
			  post-elog-additional-args " " 
			  "--entry=" entry-file " " 
;			  "--username=" post-elog-username " "
;			  "--password=" post-elog-password " "
			  (post-elog-get-list-of-files)
			  ))
    (setq current-buf (current-buffer))
    ;(switch-to-buffer (get-buffer-create "*post-plots-buffer*"))
    ;(call-process-shell-command command nil (get-buffer "*shell*") nil)
    (shell "/bin/bash")
    (switch-to-buffer (get-buffer "/bin/bash"))
    (process-send-string (get-buffer "/bin/bash") command)
    (process-send-string (get-buffer "/bin/bash") "\n")
    (process-send-string (get-buffer "/bin/bash") post-elog-username)
    (process-send-string (get-buffer "/bin/bash") "\n")
    ;(process-send-string (get-buffer "/bin/bash") post-elog-password)
    (process-send-string (get-buffer "/bin/bash") "\n")
    (process-send-eof (get-buffer "/bin/bash"))
    (switch-to-buffer current-buf)
    )
  )
I've also tried the:
(call-process-shell-command command nil (get-buffer-create "*post-elog*") nil)
I hope that the variable names are self-explanatory, but for the record, "post-elog-path-to-postPlots" is the path to my python script. (post-elog-get-list-of-files) returns a string of absolute filenames which are files to get attached to the post. Basically this allows you to post automatically to a form like this and attach files.

Re: Running shell command from elisp

Hello,

I've solved the problem by calling an asynchronous process, which is outlined in more detail in the manual. Suffice to say here is the result:
   (setq process (start-process "process" "*post-plots-buffer*" "python" 
				 post-elog-path-to-postPlots
				 post-elog-additional-args
				 (concat "--entry=" entry-file)
				 (post-elog-get-list-of-files)))
    (process-send-string process (concat post-elog-username "\n"))
    (process-send-string process (concat post-elog-password "\n\n"))