2018-09-27 23:05:04 -04:00
|
|
|
;;; core/autoload/cli.el -*- lexical-binding: t; -*-
|
|
|
|
|
2019-10-17 14:36:57 -04:00
|
|
|
;;
|
|
|
|
;;; Library
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-call-process (command &rest args)
|
|
|
|
"Execute COMMAND with ARGS synchronously.
|
|
|
|
|
|
|
|
Returns (STATUS . OUTPUT) when it is done, where STATUS is the returned error
|
|
|
|
code of the process and OUTPUT is its stdout output."
|
|
|
|
(with-temp-buffer
|
|
|
|
(cons (or (apply #'call-process command nil t nil args)
|
|
|
|
-1)
|
|
|
|
(string-trim (buffer-string)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-exec-process (command &rest args)
|
|
|
|
"Execute COMMAND with ARGS synchronously.
|
|
|
|
|
|
|
|
Unlike `doom-call-process', this pipes output to `standard-output' on the fly to
|
|
|
|
simulate 'exec' in the shell, so batch scripts could run external programs
|
|
|
|
synchronously without sacrificing their output.
|
|
|
|
|
|
|
|
Warning: freezes indefinitely on any stdin prompt."
|
|
|
|
;; FIXME Is there any way to handle prompts?
|
|
|
|
(with-temp-buffer
|
|
|
|
(cons (let ((process
|
|
|
|
(make-process :name "doom-sh"
|
|
|
|
:buffer (current-buffer)
|
|
|
|
:command (cons command args)
|
|
|
|
:connection-type 'pipe))
|
|
|
|
done-p)
|
|
|
|
(set-process-filter
|
2019-11-23 00:52:36 -05:00
|
|
|
process (lambda (_process output)
|
2019-10-19 02:34:57 -04:00
|
|
|
(princ output (current-buffer))
|
|
|
|
(princ output)))
|
2019-10-17 14:36:57 -04:00
|
|
|
(set-process-sentinel
|
|
|
|
process (lambda (process _event)
|
|
|
|
(when (memq (process-status process) '(exit stop))
|
|
|
|
(setq done-p t))))
|
|
|
|
(while (not done-p)
|
|
|
|
(sit-for 0.1))
|
|
|
|
(process-exit-status process))
|
|
|
|
(string-trim (buffer-string)))))
|