Elisp: Call Shell Command
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-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)
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-processor 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-process-shell-command NAME BUFFER COMMAND)
Use a single string for the external command and its args.
;; open files in Linux desktop (mapc (lambda (x) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" x)) ) filePathList)
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")