5

Here's a simple defun to run a shell script:

(defun bk-konsoles ()
  "Calls: bk-konsoles.bash"
  (interactive)
  (shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ")
                         (if (buffer-file-name) 
                             (file-name-directory (buffer-file-name)))
                         " &") 
                  nil nil))

If I start a program with no ampersand - it start the script, but blocks emacs until I close the program, if I don't put ampersand it gives error:

/home/boris/its/plts/goodies/bk-konsoles.bash /home/boris/scl/geekgeek/: exited abnormally with code 1.

Edit:

So now I'm using:

(defun bk-konsoles ()
  "Calls: bk-konsoles.bash"
  (interactive)
  (shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") 
                         (if (buffer-file-name) 
                             (file-name-directory (buffer-file-name))) 
                         " & disown") 
                 nil nil)
  (kill-buffer "*Shell Command Output*"))

Edit 2:

Nope - doesn't work:

(defun bk-konsoles ()
  "Calls: bk-konsoles.bash"
  (interactive)
  (let ((curDir default-directory))
    ;; (shell-command (concat "nohup " (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") curDir) nil nil)
    (shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") 
                           curDir "& disown") nil nil)
    (kill-buffer "*Shell Command Output*")))

keeps emacs busy - either with disown, or nohup.

Here's a script I'm running if it might be of help: bk-konsoles.bash

7
  • 2
    hint: use `async-shell-command' instead Commented May 26, 2012 at 14:48
  • @kindahero - async-shell-command just adds the ampersand behind the scenes if one isn't present. If that worked, then what he has posted would also work. Commented May 26, 2012 at 15:31
  • You can use disown like this: your-command & diswon. Commented May 26, 2012 at 16:37
  • @Daimrod: your-command & diswon solves it! Please make it an answer - so I can accept it. Commented May 26, 2012 at 17:49
  • I think the problem is konsole. (shell-command "x-term &") does what you expect, but (shell-command "konsole &") opens and closes konsole immediately. Something about the way konsole is started seems to be causing the problem. Commented Jun 4, 2012 at 17:42

3 Answers 3

4
+100

I think the problem is konsole.

(shell-command "xterm &")

does what you expect, opening an xterm in a new window and returning control to Emacs. However,

(shell-command "konsole &")

opens and closes konsole immediately. Something about the way konsole is started seems to be causing the problem. I think KDE apps have their own system for launching apps, but I'm not sure. In any case, I don't think the problem is on the Emacs side here.

Sign up to request clarification or add additional context in comments.

1 Comment

Just as a side note, I came here because I simply wanted to run an interactive shell within an emacs buffer window, and perhaps others will simply want to do the same, and it's pretty straight forward on a GNU Emacs install on a Debian box: "M-x term" where M is the alt key. This will run a subshell with input and output through an Emacs buffer. You can then give commands interactively. Full terminal emulation is available.
2

You can either use nohup or disown like this:

$ your_command & disown
$ nohup your_command

See this post on stackexchange for a description of the difference.

1 Comment

Cool! Take a look at the continuation of this question.
0

Oh I solved it:

(shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ")
                curDir " 2>&1 > /dev/null & disown") nil nil)

and I also call konsole with 2>&1 > /dev/null & in my bash script. Works silently!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.