Function: shell-command-to-string
shell-command-to-string is a byte-compiled function defined in
simple.el.gz.
Signature
(shell-command-to-string COMMAND)
Documentation
Execute shell command COMMAND and return its output as a string.
Use shell-quote-argument to quote dangerous characters in
COMMAND before passing it as an argument to this function.
Use this function only when a shell interpreter is needed. In
other cases, consider alternatives such as call-process or
process-lines, which do not invoke the shell. Consider using
built-in functions like rename-file instead of the external
command "mv". For more information, see Info node
(elisp)Security Considerations.
If COMMAND includes several separate commands to run one after the other, the separator between the individual commands needs to be shell- and system-dependent. In particular, the MS-Windows shell cmd.exe doesn't support commands with embedded newlines; use the "&&" separator instead.
Probably introduced at or before Emacs version 20.1.
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun shell-command-to-string (command)
"Execute shell command COMMAND and return its output as a string.
Use `shell-quote-argument' to quote dangerous characters in
COMMAND before passing it as an argument to this function.
Use this function only when a shell interpreter is needed. In
other cases, consider alternatives such as `call-process' or
`process-lines', which do not invoke the shell. Consider using
built-in functions like `rename-file' instead of the external
command \"mv\". For more information, see Info node
`(elisp)Security Considerations'.
If COMMAND includes several separate commands to run one after
the other, the separator between the individual commands needs
to be shell- and system-dependent. In particular, the MS-Windows
shell cmd.exe doesn't support commands with embedded newlines;
use the \"&&\" separator instead."
(with-output-to-string
(with-current-buffer standard-output
(shell-command command t))))