title: How do I execute a shell-command in background?
body: <p>Here's a simple defun to run a shell script:</p>
  
  
  
  <pre><code>(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)))
                           " &amp;") 
                    nil nil))
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>/home/boris/its/plts/goodies/bk-konsoles.bash /home/boris/scl/geekgeek/: exited abnormally with code 1.
  </code></pre>
  
  <p><strong>Edit</strong>: </p>
  
  <p>So now I'm using:</p>
  
  <pre><code>(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))) 
                           " &amp; disown") 
                   nil nil)
    (kill-buffer "*Shell Command Output*"))
  </code></pre>
  
  <p><strong>Edit 2</strong>:</p>
  
  <p>Nope - doesn't work:</p>
  
  <pre><code>(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 "&amp; disown") nil nil)
      (kill-buffer "*Shell Command Output*")))
  </code></pre>
  
  <p>keeps emacs busy - either with <code>disown</code>, or <code>nohup</code>.</p>
  
  <p>Here's a script I'm running if it might be of help: <a href="https://github.com/bk322/bk-goodies/blob/master/bk-konsoles.bash" rel="nofollow">bk-konsoles.bash</a></p>