comparison man/lispref/processes.texi @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children e0b8ef850996
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
58 process and returns a process object (@pxref{Asynchronous Processes}). 58 process and returns a process object (@pxref{Asynchronous Processes}).
59 The other two, @code{call-process} and @code{call-process-region}, 59 The other two, @code{call-process} and @code{call-process-region},
60 create a synchronous process and do not return a process object 60 create a synchronous process and do not return a process object
61 (@pxref{Synchronous Processes}). 61 (@pxref{Synchronous Processes}).
62 62
63 Synchronous and asynchronous processes are explained in following 63 Synchronous and asynchronous processes are explained in the following
64 sections. Since the three functions are all called in a similar 64 sections. Since the three functions are all called in a similar
65 fashion, their common arguments are described here. 65 fashion, their common arguments are described here.
66 66
67 @cindex execute program 67 @cindex execute program
68 @cindex @code{PATH} environment variable 68 @cindex @code{PATH} environment variable
96 96
97 @strong{Please note:} The argument @var{program} contains only the 97 @strong{Please note:} The argument @var{program} contains only the
98 name of the program; it may not contain any command-line arguments. You 98 name of the program; it may not contain any command-line arguments. You
99 must use @var{args} to provide those. 99 must use @var{args} to provide those.
100 100
101 If you want to use features of the shell, then invoke the shell directly
102 using, for example, @var{program} of @code{"sh"}, and @var{args} of
103 @code{"-c"} and @var{"command line..."}.
104
101 The subprocess gets its current directory from the value of 105 The subprocess gets its current directory from the value of
102 @code{default-directory} (@pxref{File Name Expansion}). 106 @code{default-directory} (@pxref{File Name Expansion}).
103 107
104 @cindex environment variables, subprocesses 108 @cindex environment variables, subprocesses
105 The subprocess inherits its environment from XEmacs; but you can 109 The subprocess inherits its environment from XEmacs; but you can
244 file)) 248 file))
245 @end group 249 @end group
246 @end smallexample 250 @end smallexample
247 @end defun 251 @end defun
248 252
249 @defun call-process-region start end program &optional delete destination display &rest args 253 @defun call-process-region start end program &optional deletep destination displayp &rest args
250 This function sends the text between @var{start} to @var{end} as 254 This function sends the text between @var{start} to @var{end} as
251 standard input to a process running @var{program}. It deletes the text 255 standard input to a process running @var{program}. It deletes the text
252 sent if @var{delete} is non-@code{nil}; this is useful when @var{buffer} 256 sent if @var{deletep} is non-@code{nil}; this is useful when @var{buffer}
253 is @code{t}, to insert the output in the current buffer. 257 is @code{t}, to insert the output in the current buffer.
254 258
255 The arguments @var{destination} and @var{display} control what to do 259 The arguments @var{destination} and @var{displayp} control what to do
256 with the output from the subprocess, and whether to update the display 260 with the output from the subprocess, and whether to update the display
257 as it comes in. For details, see the description of 261 as it comes in. For details, see the description of
258 @code{call-process}, above. If @var{destination} is the integer 0, 262 @code{call-process}, above. If @var{destination} is the integer 0,
259 @code{call-process-region} discards the output and returns @code{nil} 263 @code{call-process-region} discards the output and returns @code{nil}
260 immediately, without waiting for the subprocess to finish. 264 immediately, without waiting for the subprocess to finish.
404 in Shell mode, because they allow job control (@kbd{C-c}, @kbd{C-z}, 408 in Shell mode, because they allow job control (@kbd{C-c}, @kbd{C-z},
405 etc.) to work between the process and its children whereas pipes do not. 409 etc.) to work between the process and its children whereas pipes do not.
406 For subprocesses used for internal purposes by programs, it is often 410 For subprocesses used for internal purposes by programs, it is often
407 better to use a pipe, because they are more efficient. In addition, the 411 better to use a pipe, because they are more efficient. In addition, the
408 total number of @sc{pty}s is limited on many systems and it is good not 412 total number of @sc{pty}s is limited on many systems and it is good not
409 to waste them. 413 to waste them. A rule of thumb is to use ptys for processes the user
414 interacts with directly, and pipes for processes that are hidden from
415 the user.
410 416
411 The value @code{process-connection-type} is used when 417 The value @code{process-connection-type} is used when
412 @code{start-process} is called. So you can specify how to communicate 418 @code{start-process} is called. So you can specify how to communicate
413 with one subprocess by binding the variable around the call to 419 with one subprocess by binding the variable around the call to
414 @code{start-process}. 420 @code{start-process}.
422 428
423 To determine whether a given subprocess actually got a pipe or a 429 To determine whether a given subprocess actually got a pipe or a
424 @sc{pty}, use the function @code{process-tty-name} (@pxref{Process 430 @sc{pty}, use the function @code{process-tty-name} (@pxref{Process
425 Information}). 431 Information}).
426 @end defvar 432 @end defvar
433
434 Lisp functions that manipulate processes usually accept a @var{process}
435 argument. Besides using an actual process object for this argument, you
436 can use a process name, a buffer object, the name of a buffer, or
437 @code{nil}. Specifying a buffer or buffer name for the @var{process}
438 argument means use the process associated with the buffer (or the most
439 recent one, if there is more than one). @code{nil} means use the
440 process associated with the current buffer.
441 @xref{Process Information}.
442 @xref{Process Buffers}.
427 443
428 @node Deleting Processes 444 @node Deleting Processes
429 @section Deleting Processes 445 @section Deleting Processes
430 @cindex deleting processes 446 @cindex deleting processes
431 447
498 @result{} (#<process display-time> #<process shell>) 514 @result{} (#<process display-time> #<process shell>)
499 @end group 515 @end group
500 @end smallexample 516 @end smallexample
501 @end defun 517 @end defun
502 518
503 @defun get-process name 519 @defun get-process process-name
504 This function returns the process named @var{name}, or @code{nil} if 520 This function returns the process named @var{process-name}. If
505 there is none. An error is signaled if @var{name} is not a string. 521 @var{process-name} is a string and there is no process with that name, the
522 value is @code{nil}. If @var{process-name} is actually a process, it is
523 returned as given. (That is not very useful, so the argument is usually
524 a name.) For example:
506 525
507 @smallexample 526 @smallexample
508 @group 527 @group
509 (get-process "shell") 528 (get-process "shell")
510 @result{} #<process shell> 529 @result{} #<process shell>
536 555
537 @defun process-name process 556 @defun process-name process
538 This function returns the name of @var{process}. 557 This function returns the name of @var{process}.
539 @end defun 558 @end defun
540 559
541 @defun process-status process-name 560 @defun process-status process
542 This function returns the status of @var{process-name} as a symbol. 561 This function returns the status of @var{process} as a symbol.
543 The argument @var{process-name} must be a process, a buffer, a 562 The argument @var{process} must be a process, a buffer, a
544 process name (string) or a buffer name (string). 563 process name (string) or a buffer name (string).
545 564
546 The possible values for an actual subprocess are: 565 The possible values for an actual subprocess are:
547 566
548 @table @code 567 @table @code
559 @item closed 578 @item closed
560 for a network connection that is closed. Once a connection 579 for a network connection that is closed. Once a connection
561 is closed, you cannot reopen it, though you might be able to open 580 is closed, you cannot reopen it, though you might be able to open
562 a new connection to the same place. 581 a new connection to the same place.
563 @item nil 582 @item nil
564 if @var{process-name} is not the name of an existing process. 583 if @var{process} does not identify an existing process.
565 @end table 584 @end table
566 585
567 @smallexample 586 @smallexample
568 @group 587 @group
569 (process-status "shell") 588 (process-status "shell")
617 XEmacs, which is done with the functions in this section. You must 636 XEmacs, which is done with the functions in this section. You must
618 specify the process to send input to, and the input data to send. The 637 specify the process to send input to, and the input data to send. The
619 data appears on the ``standard input'' of the subprocess. 638 data appears on the ``standard input'' of the subprocess.
620 639
621 Some operating systems have limited space for buffered input in a 640 Some operating systems have limited space for buffered input in a
622 @sc{pty}. On these systems, Emacs sends an @sc{eof} periodically amidst 641 @sc{pty}. On these systems, XEmacs sends long input in chunks, with
623 the other characters, to force them through. For most programs, 642 @sc{eof} characters added amidst the other characters, to force the
624 these @sc{eof}s do no harm. 643 operating system to periodically drain the input buffer. For most
625 644 programs, these @sc{eof}s do no harm.
626 @defun process-send-string process-name string 645
627 This function sends @var{process-name} the contents of @var{string} as 646 @defun process-send-string process string &optional start end
628 standard input. The argument @var{process-name} must be a process or 647 This function sends @var{process} the contents of @var{string} as
629 the name of a process. If it is @code{nil}, the current buffer's 648 standard input.
630 process is used. 649
650 The argument @var{process} may be a process or the name of a process, or
651 a buffer or the name of a buffer, in which case the buffer's process is
652 used. If it is @code{nil}, the current buffer's process is used.
653
654 Optional arguments @var{start} and @var{end} specify part of @var{string};
655 see @code{substring}.
631 656
632 The function returns @code{nil}. 657 The function returns @code{nil}.
633 658
634 @smallexample 659 @smallexample
635 @group 660 @group
648 ---------- Buffer: *shell* ---------- 673 ---------- Buffer: *shell* ----------
649 @end group 674 @end group
650 @end smallexample 675 @end smallexample
651 @end defun 676 @end defun
652 677
653 @deffn Command process-send-region process-name start end 678 @defun process-send-region process start end &optional buffer
654 This function sends the text in the region defined by @var{start} and 679 This function sends the text in the region defined by @var{start} and
655 @var{end} as standard input to @var{process-name}, which is a process or 680 @var{end} as standard input to @var{process}.
656 a process name. (If it is @code{nil}, the current buffer's process is 681
657 used.) 682 The argument @var{process} may be a process or the name of a process, or
683 a buffer or the name of a buffer, in which case the buffer's process is
684 used. If it is @code{nil}, the current buffer's process is used.
658 685
659 An error is signaled unless both @var{start} and @var{end} are 686 An error is signaled unless both @var{start} and @var{end} are
660 integers or markers that indicate positions in the current buffer. (It 687 integers or markers that indicate positions in the current buffer. (It
661 is unimportant which number is larger.) 688 is unimportant which number is larger.)
662 @end deffn 689 @end defun
663 690
664 @defun process-send-eof &optional process-name 691 @defun process-send-eof &optional process
665 This function makes @var{process-name} see an end-of-file in its 692 This function makes @var{process} see an end-of-file in its
666 input. The @sc{eof} comes after any text already sent to it. 693 input. The @sc{eof} comes after any text already sent to it.
667 694
668 If @var{process-name} is not supplied, or if it is @code{nil}, then 695 @var{process} may be a process, a buffer, the name of a process or
669 this function sends the @sc{eof} to the current buffer's process. An 696 buffer, or @code{nil}, indicating the current buffer's process. An
670 error is signaled if the current buffer has no process. 697 error is signaled if @var{process} does not identify any process.
671 698
672 The function returns @var{process-name}. 699 The function returns the process object identified by @var{process}.
673 700
674 @smallexample 701 @smallexample
675 @group 702 @group
676 (process-send-eof "shell") 703 (process-send-eof "shell")
677 @result{} "shell" 704 @result{} "shell"
777 This function resumes execution of the process @var{process} by sending 804 This function resumes execution of the process @var{process} by sending
778 it the signal @code{SIGCONT}. This presumes that @var{process} was 805 it the signal @code{SIGCONT}. This presumes that @var{process} was
779 stopped previously. 806 stopped previously.
780 @end defun 807 @end defun
781 808
782 @defun signal-process pid signal 809 @deffn Command signal-process pid signal
783 This function sends a signal to the process with process id @var{pid}, 810 This function sends a signal to the process with process id @var{pid},
784 which need not be a child of XEmacs. The argument @var{signal} 811 which need not be a child of XEmacs. The argument @var{signal}
785 specifies which signal to send. 812 specifies which signal to send.
786 @end defun 813 @end deffn
787 814
788 @node Output from Processes 815 @node Output from Processes
789 @section Receiving Output from Processes 816 @section Receiving Output from Processes
790 @cindex process output 817 @cindex process output
791 @cindex output from processes 818 @cindex output from processes
860 associated with no buffer. 887 associated with no buffer.
861 @end defun 888 @end defun
862 889
863 @defun get-buffer-process buffer-or-name 890 @defun get-buffer-process buffer-or-name
864 This function returns the process associated with @var{buffer-or-name}. 891 This function returns the process associated with @var{buffer-or-name}.
865 If there are several processes associated with it, then one is chosen. 892 If there are several processes associated with @var{buffer-or-name},
866 (Presently, the one chosen is the one most recently created.) It is 893 then one is chosen. (Presently, the one chosen is the one most recently
867 usually a bad idea to have more than one process associated with the 894 created.) It is usually a bad idea to have more than one process
868 same buffer. 895 associated with the same buffer.
869 896
870 @smallexample 897 @smallexample
871 @group 898 @group
872 (get-buffer-process "*shell*") 899 (get-buffer-process "*shell*")
873 @result{} #<process shell> 900 @result{} #<process shell>
924 update the process marker, and in some cases update the value of point. 951 update the process marker, and in some cases update the value of point.
925 Here is how to do these things: 952 Here is how to do these things:
926 953
927 @smallexample 954 @smallexample
928 @group 955 @group
929 (defun ordinary-insertion-filter (proc string) 956 (defun ordinary-insertion-filter (process string)
930 (let ((old-buffer (current-buffer))) 957 (let ((old-buffer (current-buffer)))
931 (unwind-protect 958 (unwind-protect
932 (let (moving) 959 (let (moving)
933 (set-buffer (process-buffer proc)) 960 (set-buffer (process-buffer process))
934 (setq moving (= (point) (process-mark proc))) 961 (setq moving (= (point) (process-mark process)))
935 @end group 962 @end group
936 @group 963 @group
937 (save-excursion 964 (save-excursion
938 ;; @r{Insert the text, moving the process-marker.} 965 ;; @r{Insert the text, moving the process-marker.}
939 (goto-char (process-mark proc)) 966 (goto-char (process-mark process))
940 (insert string) 967 (insert string)
941 (set-marker (process-mark proc) (point))) 968 (set-marker (process-mark process) (point)))
942 (if moving (goto-char (process-mark proc)))) 969 (if moving (goto-char (process-mark process))))
943 (set-buffer old-buffer)))) 970 (set-buffer old-buffer))))
944 @end group 971 @end group
945 @end smallexample 972 @end smallexample
946 973
947 @noindent 974 @noindent
952 To make the filter force the process buffer to be visible whenever new 979 To make the filter force the process buffer to be visible whenever new
953 text arrives, insert the following line just before the 980 text arrives, insert the following line just before the
954 @code{unwind-protect}: 981 @code{unwind-protect}:
955 982
956 @smallexample 983 @smallexample
957 (display-buffer (process-buffer proc)) 984 (display-buffer (process-buffer process))
958 @end smallexample 985 @end smallexample
959 986
960 To force point to move to the end of the new output no matter where 987 To force point to move to the end of the new output no matter where
961 it was previously, eliminate the variable @code{moving} and call 988 it was previously, eliminate the variable @code{moving} and call
962 @code{goto-char} unconditionally. 989 @code{goto-char} unconditionally.
1030 1057
1031 @smallexample 1058 @smallexample
1032 @group 1059 @group
1033 ;; @r{Insert input in the buffer specified by @code{my-shell-buffer}} 1060 ;; @r{Insert input in the buffer specified by @code{my-shell-buffer}}
1034 ;; @r{and make sure that buffer is shown in some window.} 1061 ;; @r{and make sure that buffer is shown in some window.}
1035 (defun my-process-filter (proc str) 1062 (defun my-process-filter (process string)
1036 (let ((cur (selected-window)) 1063 (let ((cur (selected-window))
1037 (pop-up-windows t)) 1064 (pop-up-windows t))
1038 (pop-to-buffer my-shell-buffer) 1065 (pop-to-buffer my-shell-buffer)
1039 @end group 1066 @end group
1040 @group 1067 @group
1041 (goto-char (point-max)) 1068 (goto-char (point-max))
1042 (insert str) 1069 (insert string)
1043 (set-marker (process-mark proc) (point-max)) 1070 (set-marker (process-mark process) (point-max))
1044 (select-window cur))) 1071 (select-window cur)))
1045 @end group 1072 @end group
1046 @end smallexample 1073 @end smallexample
1047 @end ignore 1074 @end ignore
1048 1075
1252 from those representing subprocesses with the @code{process-status} 1279 from those representing subprocesses with the @code{process-status}
1253 function. It always returns either @code{open} or @code{closed} for a 1280 function. It always returns either @code{open} or @code{closed} for a
1254 network connection, and it never returns either of those values for a 1281 network connection, and it never returns either of those values for a
1255 real subprocess. @xref{Process Information}. 1282 real subprocess. @xref{Process Information}.
1256 1283
1257 @defun open-network-stream name buffer-or-name host service 1284 @defun open-network-stream name buffer-or-name host service &optional protocol
1258 This function opens a TCP connection for a service to a host. It 1285 This function opens a TCP connection for a service to a host. It
1259 returns a process object to represent the connection. 1286 returns a process object to represent the connection.
1260 1287
1288 Input and output work as for other process objects.
1289 @code{delete-process} closes the connection.
1290
1261 The @var{name} argument specifies the name for the process object. It 1291 The @var{name} argument specifies the name for the process object. It
1262 is modified as necessary to make it unique. 1292 is modified as necessary to make it unique.
1263 1293
1264 The @var{buffer-or-name} argument is the buffer to associate with the 1294 The @var{buffer-or-name} argument is the buffer to associate with the
1265 connection. Output from the connection is inserted in the buffer, 1295 connection. It can be a buffer or the name of one. Output from the
1266 unless you specify a filter function to handle the output. If 1296 connection is inserted in the buffer, unless you specify a filter
1267 @var{buffer-or-name} is @code{nil}, it means that the connection is not 1297 function to handle the output. If @var{buffer-or-name} is @code{nil},
1268 associated with any buffer. 1298 it means that the connection is not associated with any buffer.
1269 1299
1270 The arguments @var{host} and @var{service} specify where to connect to; 1300 The arguments @var{host} and @var{service} specify where to connect to;
1271 @var{host} is the host name or IP address (a string), and @var{service} 1301 @var{host} is the host name or IP address (a string), and @var{service}
1272 is the name of a defined network service (a string) or a port number (an 1302 is the name of a defined network service (a string) or a port number (an
1273 integer). 1303 integer).
1274 @end defun 1304
1305 Optional fifth arg @var{protocol} is the network protocol to use.
1306 Currently only @code{tcp} (Transmission Control Protocol) and @code{udp}
1307 (User Datagram Protocol) are supported. When omitted, @code{tcp} is assumed.
1308
1309 Output via @code{process-send-string} and input via buffer or filter
1310 (see @code{set-process-filter}) are stream-oriented. That means
1311 UDP datagrams are not guaranteed to be sent and received in
1312 discrete packets. (But small datagrams around 500 bytes that are not
1313 truncated by @code{process-send-string} are usually fine.) Note further
1314 that the UDP protocol does not guard against lost packets.
1315 @end defun