Page 1 of 1

[SOLVED] Running shell command from elisp

PostPosted: Mon Jul 05, 2010 3:04 pm
by ocmsRzr

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.



Re: Running shell command from elisp

PostPosted: Tue Jul 06, 2010 1:23 am
by ocmsRzr

Didn't occur to me to also post my attempts at solving the problem.
Code: Select all
(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 " "
    (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:
Code: Select all
(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

PostPosted: Fri Jul 23, 2010 4:19 pm
by ocmsRzr

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:
Code: Select all
   (setq process (start-process "process" "*post-plots-buffer*" "python"
             (concat "--entry=" entry-file)
    (process-send-string process (concat post-elog-username "\n"))
    (process-send-string process (concat post-elog-password "\n\n"))