After an asynchronous process is created, Emacs and the subprocess both continue running immediately. The process thereafter runs in parallel with Emacs, and the two can communicate with each other using the functions described in the following sections. However, communication is only partially asynchronous: Emacs sends data to the process only when certain functions are called, and Emacs accepts data from the process only when Emacs is waiting for input or for a time delay.
Here we describe how to create an asynchronous process.
This function creates a new asynchronous subprocess and starts the program program running in it. It returns a process object that stands for the new subprocess in Lisp. The argument name specifies the name for the process object; if a process with this name already exists, then name is modified (by appending ‘<1>’, etc.) to be unique. The buffer buffer-or-name is the buffer to associate with the process.
The remaining arguments, args, are strings that specify command line arguments for the program.
In the example below, the first process is started and runs (rather, sleeps) for 100 seconds. Meanwhile, the second process is started, and given the name ‘my-process<1>’ for the sake of uniqueness. It inserts the directory listing at the end of the buffer ‘foo’, before the first process finishes. Then it finishes, and a message to that effect is inserted in the buffer. Much later, the first process finishes, and another message is inserted in the buffer for it.(start-process "my-process" "foo" "sleep" "100") ⇒ #<process my-process> (start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin") ⇒ #<process my-process<1>> ---------- Buffer: foo ---------- total 2 lrwxrwxrwx 1 lewis 14 Jul 22 10:12 gnuemacs --> /emacs -rwxrwxrwx 1 lewis 19 Jul 30 21:02 lemon Process my-process<1> finished Process my-process finished ---------- Buffer: foo ----------
start-process, this function starts a new asynchronous subprocess running program in it, and returns its process object—when
default-directoryis not a magic file name.
default-directoryis magic, the function invokes its file handler instead. This handler ought to run program, perhaps on the local host, perhaps on a remote host that corresponds to
default-directory. In the latter case, the local part of
default-directorybecomes the working directory of the process.
This function does not try to invoke file name handlers for program or for the program-args.
Some file handlers may not support
ange-ftp-hook-function). In such cases, the function does nothing and returns
This function is like
start-processexcept that it uses a shell to execute the specified command. The argument command is a shell command name. The variable
shell-file-namespecifies which shell to use.
The point of running a program through the shell, rather than directly with
start-process, is so that you can employ shell features such as wildcards in the arguments. It follows that if you include an arbitrary user-specified arguments in the command, you should quote it with
shell-quote-argumentfirst, so that any special shell characters do not have their special shell meanings. See Shell Arguments.
This function is like
start-process-shell-command, but uses
start-file-processinternally. By this, command can be executed also on remote hosts, depending on
PTYs are usually preferable for processes visible to the user, as in Shell mode, because they allow job control (C-c, C-z, etc.) to work between the process and its children, whereas pipes do not. For subprocesses used for internal purposes by programs, it is often better to use a pipe, because they are more efficient. In addition, the total number of PTYs is limited on many systems and it is good not to waste them.
The value of
process-connection-typetakes effect when
start-processis called. So you can specify how to communicate with one subprocess by binding the variable around the call to
start-process.(let ((process-connection-type nil)) ; Use a pipe. (start-process ...))
To determine whether a given subprocess actually got a pipe or a PTY, use the function
process-tty-name(see Process Information).