Function: exec-path-from-shell-printf
exec-path-from-shell-printf is a natively compiled function defined in
exec-path-from-shell.el.
Signature
(exec-path-from-shell-printf STR &optional ARGS)
Documentation
Return the result of printing STR in the user's shell.
Executes the shell as interactive login shell.
STR is inserted literally in a single-quoted argument to printf, and may therefore contain backslashed escape sequences understood by printf.
ARGS is an optional list of args which will be inserted by printf in place of any % placeholders in STR. ARGS are not automatically shell-escaped, so they may contain $ etc.
Source Code
;; Defined in /nix/store/a3f7aq5s6rdw5arrqvyppbs5jfrlsxa3-emacs-packages-deps/share/emacs/site-lisp/elpa/exec-path-from-shell-20260423.1833/exec-path-from-shell.el
(defun exec-path-from-shell-printf (str &optional args)
"Return the result of printing STR in the user's shell.
Executes the shell as interactive login shell.
STR is inserted literally in a single-quoted argument to printf,
and may therefore contain backslashed escape sequences understood
by printf.
ARGS is an optional list of args which will be inserted by printf
in place of any % placeholders in STR. ARGS are not automatically
shell-escaped, so they may contain $ etc."
(let* ((printf-bin (or (executable-find "printf") "printf"))
(printf-command
(concat (shell-quote-argument printf-bin)
" '__RESULT\\000" str "\\000__RESULT' "
(mapconcat #'exec-path-from-shell--double-quote args " ")))
(shell (exec-path-from-shell--shell))
(shell-args (append exec-path-from-shell-arguments
(list "-c"
(if (exec-path-from-shell--standard-shell-p shell)
printf-command
(concat "sh -c " (shell-quote-argument printf-command)))))))
(with-temp-buffer
(exec-path-from-shell--debug "Invoking shell %s with args %S" shell shell-args)
(let ((exit-code (exec-path-from-shell--warn-duration
(apply #'call-process shell nil t nil shell-args))))
(exec-path-from-shell--debug "Shell printed: %S" (buffer-string))
(unless (zerop exit-code)
(error "Non-zero exit code from shell %s invoked with args %S. Output was:\n%S"
shell shell-args (buffer-string))))
(goto-char (point-min))
(if (re-search-forward "__RESULT\0\\(.*\\)\0__RESULT" nil t)
(match-string 1)
(error "Expected printf output from shell, but got: %S" (buffer-string))))))