[SOLVED] Running shell command from elisp

Discussion of Emacs Lisp

[SOLVED] Running shell command from elisp

Postby ocmsRzr » Mon Jul 05, 2010 3:04 pm

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 Fri Jul 23, 2010 4:19 pm, edited 1 time in total.
ocmsRzr
 
Posts: 3
Joined: Mon Jul 05, 2010 12:33 pm

Re: Running shell command from elisp

Postby ocmsRzr » Tue Jul 06, 2010 1:23 am

Hi,

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 " "
           (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:
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.
ocmsRzr
 
Posts: 3
Joined: Mon Jul 05, 2010 12:33 pm

Re: Running shell command from elisp

Postby ocmsRzr » Fri Jul 23, 2010 4:19 pm

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:
Code: Select all
   (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"))
 
ocmsRzr
 
Posts: 3
Joined: Mon Jul 05, 2010 12:33 pm


Return to Emacs Lisp

Who is online

Users browsing this forum: No registered users and 0 guests