Emacs: shell-command-to-string

Rating: 5

You can use shell-command-to-string in elisp to get the result of running a shell command.

Examples

;; Get the current git branch.
(shell-command-to-string "git rev-parse --abbrev-ref HEAD")
;; Ignore stderr output.
(shell-command-to-string "git rev-parse --abbrev-ref HEAD 2>/dev/null")
More Info