Mercurial > emacs
comparison lispref/processes.texi @ 21682:90da2489c498
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 20 Apr 1998 17:43:57 +0000 |
parents | 66d807bdc5b4 |
children | d4ac295a98b3 |
comparison
equal
deleted
inserted
replaced
21681:11eafe90b842 | 21682:90da2489c498 |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | 2 @c This is part of the GNU Emacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. |
4 @c See the file elisp.texi for copying conditions. | 4 @c See the file elisp.texi for copying conditions. |
5 @setfilename ../info/processes | 5 @setfilename ../info/processes |
6 @node Processes, System Interface, Abbrevs, Top | 6 @node Processes, Display, Abbrevs, Top |
7 @chapter Processes | 7 @chapter Processes |
8 @cindex child process | 8 @cindex child process |
9 @cindex parent process | 9 @cindex parent process |
10 @cindex subprocess | 10 @cindex subprocess |
11 @cindex process | 11 @cindex process |
33 @end defun | 33 @end defun |
34 | 34 |
35 @menu | 35 @menu |
36 * Subprocess Creation:: Functions that start subprocesses. | 36 * Subprocess Creation:: Functions that start subprocesses. |
37 * Synchronous Processes:: Details of using synchronous subprocesses. | 37 * Synchronous Processes:: Details of using synchronous subprocesses. |
38 * MS-DOS Subprocesses:: On MS-DOS, you must indicate text vs binary | |
39 for data sent to and from a subprocess. | |
40 * Asynchronous Processes:: Starting up an asynchronous subprocess. | 38 * Asynchronous Processes:: Starting up an asynchronous subprocess. |
41 * Deleting Processes:: Eliminating an asynchronous subprocess. | 39 * Deleting Processes:: Eliminating an asynchronous subprocess. |
42 * Process Information:: Accessing run-status and other attributes. | 40 * Process Information:: Accessing run-status and other attributes. |
43 * Input to Processes:: Sending input to an asynchronous subprocess. | 41 * Input to Processes:: Sending input to an asynchronous subprocess. |
44 * Signals to Processes:: Stopping, continuing or interrupting | 42 * Signals to Processes:: Stopping, continuing or interrupting |
125 The value of @code{exec-path} is used by @code{call-process} and | 123 The value of @code{exec-path} is used by @code{call-process} and |
126 @code{start-process} when the @var{program} argument is not an absolute | 124 @code{start-process} when the @var{program} argument is not an absolute |
127 file name. | 125 file name. |
128 @end defopt | 126 @end defopt |
129 | 127 |
128 @node Shell Arguments | |
129 @section Shell Arguments | |
130 | |
131 Lisp programs sometimes need to run a shell and give it a command | |
132 which contains file names that were specified by the user. These | |
133 programs ought to be able to support any valid file name. But the shell | |
134 gives special treatment to certain characters, and if these characters | |
135 occur in the file name, they will confuse the shell. To handle these | |
136 characters, use the function @code{shell-quote-argument}: | |
137 | |
138 @defun shell-quote-argument argument | |
139 This function returns a string which represents, in shell syntax, | |
140 an argument whose actual contents are @var{argument}. It should | |
141 work reliably to concatenate the return value into a shell command | |
142 and then pass it to a shell for execution. | |
143 | |
144 Precisely what this function does depends on your operating system. The | |
145 function is designed to work with the usual shell syntax; if you use an | |
146 unusual shell, you will need to redefine this function. On MS-DOS, the | |
147 function returns @var{argument} unchanged; while this is not really | |
148 correct, it is the best one can do, since the MS-DOS shell has no | |
149 quoting features. | |
150 | |
151 @example | |
152 ;; @r{This example shows the behavior on GNU and Unix systems.} | |
153 (shell-quote-argument "foo > bar") | |
154 @result{} "foo\\ \\>\\ bar" | |
155 @end example | |
156 | |
157 Here's an example of using @code{shell-quote-argument} to construct | |
158 a shell command: | |
159 | |
160 @example | |
161 (concat "diff -c " | |
162 (shell-quote-argument oldfile) | |
163 " " | |
164 (shell-quote-argument newfile)) | |
165 @end example | |
166 @end defun | |
167 | |
130 @node Synchronous Processes | 168 @node Synchronous Processes |
131 @section Creating a Synchronous Process | 169 @section Creating a Synchronous Process |
132 @cindex synchronous subprocess | 170 @cindex synchronous subprocess |
133 | 171 |
134 After a @dfn{synchronous process} is created, Emacs waits for the | 172 After a @dfn{synchronous process} is created, Emacs waits for the |
143 the subprocess with a @code{SIGINT} signal; but it waits until the | 181 the subprocess with a @code{SIGINT} signal; but it waits until the |
144 subprocess actually terminates before quitting. If during that time the | 182 subprocess actually terminates before quitting. If during that time the |
145 user types another @kbd{C-g}, that kills the subprocess instantly with | 183 user types another @kbd{C-g}, that kills the subprocess instantly with |
146 @code{SIGKILL} and quits immediately. @xref{Quitting}. | 184 @code{SIGKILL} and quits immediately. @xref{Quitting}. |
147 | 185 |
148 The synchronous subprocess functions returned @code{nil} in version | 186 The synchronous subprocess functions return an indication of how the |
149 18. Now they return an indication of how the process terminated. | 187 process terminated. |
150 | 188 |
151 The output from a synchronous subprocess is generally decoded using a | 189 The output from a synchronous subprocess is generally decoded using a |
152 coding system, much like text read from a file. The input sent to a | 190 coding system, much like text read from a file. The input sent to a |
153 subprocess by @code{call-process-region} is encoded using a coding | 191 subprocess by @code{call-process-region} is encoded using a coding |
154 system, much like text written into a file. @xref{Coding Systems}. | 192 system, much like text written into a file. @xref{Coding Systems}. |
193 On Microsoft operating systems, additional variables control | |
194 the conversion for end-of-line (@pxref{MS-DOS Subprocesses}). | |
155 | 195 |
156 @defun call-process program &optional infile destination display &rest args | 196 @defun call-process program &optional infile destination display &rest args |
157 This function calls @var{program} in a separate process and waits for | 197 This function calls @var{program} in a separate process and waits for |
158 it to finish. | 198 it to finish. |
159 | 199 |
166 @item a buffer | 206 @item a buffer |
167 Insert the output in that buffer, before point. This includes both the | 207 Insert the output in that buffer, before point. This includes both the |
168 standard output stream and the standard error stream of the process. | 208 standard output stream and the standard error stream of the process. |
169 | 209 |
170 @item a string | 210 @item a string |
171 Find the buffer with that name, then insert the output in that buffer, | 211 Insert the output in a buffer with that name, before point. |
172 before point. | |
173 | 212 |
174 @item @code{t} | 213 @item @code{t} |
175 Insert the output in the current buffer, before point. | 214 Insert the output in the current buffer, before point. |
176 | 215 |
177 @item @code{nil} | 216 @item @code{nil} |
188 | 227 |
189 @item (@var{real-destination} @var{error-destination}) | 228 @item (@var{real-destination} @var{error-destination}) |
190 Keep the standard output stream separate from the standard error stream; | 229 Keep the standard output stream separate from the standard error stream; |
191 deal with the ordinary output as specified by @var{real-destination}, | 230 deal with the ordinary output as specified by @var{real-destination}, |
192 and dispose of the error output according to @var{error-destination}. | 231 and dispose of the error output according to @var{error-destination}. |
193 The value @code{nil} means discard it, @code{t} means mix it with the | 232 If @var{error-destination} is @code{nil}, that means to discard the |
194 ordinary output, and a string specifies a file name to redirect error | 233 error output, @code{t} means mix it with the ordinary output, and a |
195 output into. | 234 string specifies a file name to redirect error output into. |
196 | 235 |
197 You can't directly specify a buffer to put the error output in; that is | 236 You can't directly specify a buffer to put the error output in; that is |
198 too difficult to implement. But you can achieve this result by sending | 237 too difficult to implement. But you can achieve this result by sending |
199 the error output to a temporary file and then inserting the file into a | 238 the error output to a temporary file and then inserting the file into a |
200 buffer. | 239 buffer. |
235 | 274 |
236 ---------- Buffer: bar ---------- | 275 ---------- Buffer: bar ---------- |
237 @end group | 276 @end group |
238 @end smallexample | 277 @end smallexample |
239 | 278 |
240 The @code{insert-directory} function contains a good example of the use | 279 Here is a good example of the use of @code{call-process}, which used to |
241 of @code{call-process}: | 280 be found in the definition of @code{insert-directory}: |
242 | 281 |
243 @smallexample | 282 @smallexample |
244 @group | 283 @group |
245 (call-process insert-directory-program nil t nil switches | 284 (call-process insert-directory-program nil t nil @var{switches} |
246 (if full-directory-p | 285 (if full-directory-p |
247 (concat (file-name-as-directory file) ".") | 286 (concat (file-name-as-directory file) ".") |
248 file)) | 287 file)) |
249 @end group | 288 @end group |
250 @end smallexample | 289 @end smallexample |
315 @tindex shell-command-to-string | 354 @tindex shell-command-to-string |
316 @defun shell-command-to-string command | 355 @defun shell-command-to-string command |
317 This function executes @var{command} (a string) as a shell command, | 356 This function executes @var{command} (a string) as a shell command, |
318 then returns the command's output as a string. | 357 then returns the command's output as a string. |
319 @end defun | 358 @end defun |
320 | |
321 @node MS-DOS Subprocesses | |
322 @section MS-DOS Subprocesses | |
323 | |
324 On MS-DOS, you must indicate whether the data going to and from | |
325 a synchronous subprocess are text or binary. Text data requires | |
326 translation between the end-of-line convention used within Emacs | |
327 (a single newline character) and the convention used outside Emacs | |
328 (the two-character sequence, @sc{crlf}). | |
329 | |
330 The variable @code{binary-process-input} applies to input sent to the | |
331 subprocess, and @code{binary-process-output} applies to output received | |
332 from it. A non-@code{nil} value means the data is non-text; @code{nil} | |
333 means the data is text, and calls for conversion. | |
334 | |
335 @defvar binary-process-input | |
336 If this variable is @code{nil}, convert newlines to @sc{crlf} sequences in | |
337 the input to a synchronous subprocess. | |
338 @end defvar | |
339 | |
340 @defvar binary-process-output | |
341 If this variable is @code{nil}, convert @sc{crlf} sequences to newlines in | |
342 the output from a synchronous subprocess. | |
343 @end defvar | |
344 | |
345 @xref{Files and MS-DOS}, for related information. | |
346 | 359 |
347 @node Asynchronous Processes | 360 @node Asynchronous Processes |
348 @section Creating an Asynchronous Process | 361 @section Creating an Asynchronous Process |
349 @cindex asynchronous subprocess | 362 @cindex asynchronous subprocess |
350 | 363 |
401 This function is like @code{start-process} except that it uses a shell | 414 This function is like @code{start-process} except that it uses a shell |
402 to execute the specified command. The argument @var{command} is a shell | 415 to execute the specified command. The argument @var{command} is a shell |
403 command name, and @var{command-args} are the arguments for the shell | 416 command name, and @var{command-args} are the arguments for the shell |
404 command. The variable @code{shell-file-name} specifies which shell to | 417 command. The variable @code{shell-file-name} specifies which shell to |
405 use. | 418 use. |
419 | |
420 The point of running a program through the shell, rather than directly | |
421 with @code{start-process}, is so that you can employ shell features such | |
422 as wildcards in the arguments. It follows that if you include an | |
423 arbitrary user-specified filename in the command, you should quote it | |
424 with @code{shell-quote-argument} first, so that any special shell | |
425 characters in the file name do @emph{not} have their special shell | |
426 meanings. @xref{Shell Arguments}. | |
406 @end defun | 427 @end defun |
407 | 428 |
408 @defvar process-connection-type | 429 @defvar process-connection-type |
409 @cindex pipes | 430 @cindex pipes |
410 @cindex @sc{pty}s | 431 @cindex @sc{pty}s |
600 @end smallexample | 621 @end smallexample |
601 | 622 |
602 For a network connection, @code{process-status} returns one of the symbols | 623 For a network connection, @code{process-status} returns one of the symbols |
603 @code{open} or @code{closed}. The latter means that the other side | 624 @code{open} or @code{closed}. The latter means that the other side |
604 closed the connection, or Emacs did @code{delete-process}. | 625 closed the connection, or Emacs did @code{delete-process}. |
605 | |
606 In Emacs version 18, the status of a network connection was @code{run} | |
607 if open, and @code{exit} if closed. | |
608 @end defun | 626 @end defun |
609 | 627 |
610 @defun process-exit-status process | 628 @defun process-exit-status process |
611 This function returns the exit status of @var{process} or the signal | 629 This function returns the exit status of @var{process} or the signal |
612 number that killed it. (Use the result of @code{process-status} to | 630 number that killed it. (Use the result of @code{process-status} to |
626 This function returns a cons cell describing the coding systems in use | 644 This function returns a cons cell describing the coding systems in use |
627 for decoding output from @var{process} and for encoding input to | 645 for decoding output from @var{process} and for encoding input to |
628 @var{process} (@pxref{Coding Systems}). The value has this form: | 646 @var{process} (@pxref{Coding Systems}). The value has this form: |
629 | 647 |
630 @example | 648 @example |
631 (@var{coding-system-for-decoding} | 649 (@var{coding-system-for-decoding} . @var{coding-system-for-encoding}) |
632 . @var{coding-system-for-encoding}) | |
633 @end example | 650 @end example |
634 @end defun | 651 @end defun |
635 | 652 |
636 @tindex set-process-coding-system | 653 @tindex set-process-coding-system |
637 @defun set-process-coding-system process decoding-system encoding-system | 654 @defun set-process-coding-system process decoding-system encoding-system |
787 @defun stop-process &optional process-name current-group | 804 @defun stop-process &optional process-name current-group |
788 This function stops the process @var{process-name} by sending the | 805 This function stops the process @var{process-name} by sending the |
789 signal @code{SIGTSTP}. Use @code{continue-process} to resume its | 806 signal @code{SIGTSTP}. Use @code{continue-process} to resume its |
790 execution. | 807 execution. |
791 | 808 |
792 On systems with job control, outside of Emacs)\, the ``stop character'' | 809 Outside of Emacs, on systems with job control, the ``stop character'' |
793 (usually @kbd{C-z}) normally sends this signal. When | 810 (usually @kbd{C-z}) normally sends this signal. When |
794 @var{current-group} is non-@code{nil}, you can think of this function as | 811 @var{current-group} is non-@code{nil}, you can think of this function as |
795 ``typing @kbd{C-z}'' on the terminal Emacs uses to communicate with the | 812 ``typing @kbd{C-z}'' on the terminal Emacs uses to communicate with the |
796 subprocess. | 813 subprocess. |
797 @end defun | 814 @end defun |