Elisp: Call Shell Command

By Xah Lee. Date: . Last updated: .

Call Shell Command, Wait, Get Result

Call a shell command, wait for it to finish.
Call a shell command, wait for it to finish, get its output.
; call a shell command
(shell-command "ls")
; call a shell command and get its output
(shell-command-to-string "ls")

Call Shell, No Wait

Start a program in a subprocess. Return the process object for it. NAME is name for process. It is modified if necessary to make it unique. BUFFER is the buffer (or buffer name) to associate with the process.
Process output (both standard output and standard error streams) goes at end of BUFFER, unless you specify a filter function to handle the output. BUFFER may also be nil, meaning that this process is not associated with any buffer.
PROGRAM is the program file name. It is searched for in exec-path. If nil, just associate a pty with the buffer. Remaining arguments PROGRAM-ARGS are strings to give program as arguments.
If you want to separate standard output from standard error, use make-process or invoke the command through a shell and redirect one of them using the shell syntax.
The process runs in default-directory if that is local (as determined by unhandled-file-name-directory), or "~" otherwise. If you want to run a process in a remote directory use start-file-process.
(start-process-shell-command NAME BUFFER COMMAND)
Use a single string for the external command and its args.
;; open files in Linux desktop
 (lambda (x)
   (let ((process-connection-type nil))
     (start-process "" nil "xdg-open" x)) )

Call PowerShell

Here's a example of how to call a PowerShell Core command.

;; on Microsoft Windows 10, call PowerShell Core to generate UUID
(shell-command "pwsh.exe -Command [guid]::NewGuid().toString()" t)
;; on macOS, call PowerShell Core to generate UUID
(shell-command "pwsh -Command '[guid]::NewGuid().toString()'" t)


(info "(elisp) Asynchronous Processes")

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode



Basic Functions

Writing Command

Writing Script

Lisp Data Structure

Lisp Symbol

Elisp Misc