File: processes.texi

package info (click to toggle)
elisp-manual-ja 20-2.5-jp-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,996 kB
  • ctags: 239
  • sloc: lisp: 2,837; perl: 182; makefile: 45; sh: 16
file content (2121 lines) | stat: -rw-r--r-- 98,661 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
@c See the file elisp.texi for copying conditions.
@setfilename ../info/processes
@node Processes, Display, Abbrevs, Top
@c @chapter Processes
@chapter $B%W%m%;%9(B
@c @cindex child process
@c @cindex parent process
@c @cindex subprocess
@c @cindex process
@cindex $B;R%W%m%;%9(B
@cindex $B?F%W%m%;%9(B
@cindex $B%5%V%W%m%;%9(B
@cindex $B%W%m%;%9(B

@c   In the terminology of operating systems, a @dfn{process} is a space in
@c which a program can execute.  Emacs runs in a process.  Emacs Lisp
@c programs can invoke other programs in processes of their own.  These are
@c called @dfn{subprocesses} or @dfn{child processes} of the Emacs process,
@c which is their @dfn{parent process}.
$B%*%Z%l!<%F%#%s%0%7%9%F%`$NMQ8l$G$O!"(B
@dfn{$B%W%m%;%9(B}$B!J(Bprocess$B!K$H$O!"%W%m%0%i%`$r<B9T$9$k6u4V$N$3$H$G$9!#(B
Emacs$B$O%W%m%;%9$H$7$FF0$$$F$$$^$9!#(B
Emacs Lisp$B$N%W%m%0%i%`$G$O!"(B
$BFH<+$N%W%m%;%9$H$7$FB>$N%W%m%0%i%`$r5/F0$G$-$^$9!#(B
$B$=$l$i$O!"(BEmacs$B%W%m%;%9$N(B@dfn{$B%5%V%W%m%;%9(B}$B!J(Bsubprocess$B!K$H$+(B
@dfn{$B;R%W%m%;%9(B}$B!J(Bchild process$B!K$H8F$P$l!"(B
Emacs$B%W%m%;%9$O$=$l$i$N(B@dfn{$B?F%W%m%;%9(B}$B!J(Bparent process$B!K$G$9!#(B

@c   A subprocess of Emacs may be @dfn{synchronous} or @dfn{asynchronous},
@c depending on how it is created.  When you create a synchronous
@c subprocess, the Lisp program waits for the subprocess to terminate
@c before continuing execution.  When you create an asynchronous
@c subprocess, it can run in parallel with the Lisp program.  This kind of
@c subprocess is represented within Emacs by a Lisp object which is also
@c called a ``process''.  Lisp programs can use this object to communicate
@c with the subprocess or to control it.  For example, you can send
@c signals, obtain status information, receive output from the process, or
@c send input to it.
Emacs$B$N%5%V%W%m%;%9$O!"$=$l$r:n@.$9$kJ}K!$K0MB8$7$F!"(B
@dfn{$BF14|(B}$B!J(Bsynchronous$B!K$G$"$k$+(B@dfn{$BHsF14|(B}$B!J(Basynchronous$B!K$G$9!#(B
$BF14|%5%V%W%m%;%9$r:n@.$9$k$H!"(B
Lisp$B%W%m%0%i%`$O<B9T$r7QB3$9$k$^$($K$=$N%5%V%W%m%;%9$N=*N;$rBT$A$^$9!#(B
$BHsF14|%5%V%W%m%;%9$r:n@.$9$k$H!"$=$l$O(BLisp$B%W%m%0%i%`$HJB9T$7$FF0:n$7$^$9!#(B
$B$3$N<o$N%5%V%W%m%;%9$O!"(BEmacs$BFbIt$G$O$d$O$j!X%W%m%;%9!Y$H8F$P$l$k(B
Lisp$B%*%V%8%'%/%H$GI=8=$5$l$^$9!#(B
Lisp$B%W%m%0%i%`$O$3$N%*%V%8%'%/%H$rMQ$$$F(B
$B%5%V%W%m%;%9$HDL?.$7$?$j$=$l$r@)8f$G$-$^$9!#(B
$B$?$H$($P!"%7%0%J%k$rAw$C$?$j!">uBV>pJs$r<hF@$7$?$j!"(B
$B%W%m%;%9$+$i$N=PNO$r<u$1<h$C$?$j!"%W%m%;%9$XF~NO$rAw$l$^$9!#(B

@defun processp object
@c This function returns @code{t} if @var{object} is a process,
@c @code{nil} otherwise.
$B$3$N4X?t$O!"(B@var{object}$B$,%W%m%;%9$G$"$l$P(B@code{t}$B$rJV$7!"(B
$B$5$b$J$1$l$P(B@code{nil}$B$rJV$9!#(B
@end defun

@menu
* Subprocess Creation::      Functions that start subprocesses.
* Shell Arguments::          Quoting an argument to pass it to a shell.
* Synchronous Processes::    Details of using synchronous subprocesses.
* Asynchronous Processes::   Starting up an asynchronous subprocess.
* Deleting Processes::       Eliminating an asynchronous subprocess.
* Process Information::      Accessing run-status and other attributes.
* Input to Processes::       Sending input to an asynchronous subprocess.
* Signals to Processes::     Stopping, continuing or interrupting
                               an asynchronous subprocess.
* Output from Processes::    Collecting output from an asynchronous subprocess.
* Sentinels::                Sentinels run when process run-status changes.
* Transaction Queues::	     Transaction-based communication with subprocesses.
* Network::                  Opening network connections.
@end menu

@node Subprocess Creation
@c @section Functions that Create Subprocesses
@section $B%5%V%W%m%;%9:n@.4X?t(B

@c   There are three functions that create a new subprocess in which to run
@c a program.  One of them, @code{start-process}, creates an asynchronous
@c process and returns a process object (@pxref{Asynchronous Processes}).
@c The other two, @code{call-process} and @code{call-process-region},
@c create a synchronous process and do not return a process object
@c (@pxref{Synchronous Processes}).
$B%W%m%0%i%`$r<B9T$9$k$?$a$K?7$?$J%5%V%W%m%;%9$r:n$k4X?t$,(B3$B$D$"$j$^$9!#(B
$B$=$N(B1$B$D(B@code{start-process}$B$O!"HsF14|%W%m%;%9$r:n@.$7$F(B
$B%W%m%;%9%*%V%8%'%/%H$rJV$7$^$9!J(B@pxref{Asynchronous Processes}$B!K!#(B
$B;D$j$N(B2$B$D!"(B@code{call-process}$B$H(B@code{call-process-region}$B$O(B
$BF14|%W%m%;%9$r:n@.$7$^$9$,!"%W%m%;%9%*%V%8%'%/%H$OJV$7$^$;$s(B
$B!J(B@pxref{Synchronous Processes}$B!K!#(B

@c   Synchronous and asynchronous processes are explained in following
@c sections.  Since the three functions are all called in a similar
@c fashion, their common arguments are described here.
$BF14|!?HsF14|%W%m%;%9$K$D$$$F$O0J2<$N@a$K=R$Y$^$9!#(B
3$B$D$N4X?t$N8F$S=P$7J}$ON`;w$7$F$$$k$N$G!"(B
$B$3$3$G$O$=$l$i$K6&DL$J0z?t$K$D$$$F=R$Y$^$9!#(B

@c @cindex execute program
@c @cindex @code{PATH} environment variable
@c @cindex @code{HOME} environment variable
@cindex $B%W%m%0%i%`$N<B9T(B
@cindex $B<B9T!"(B
@cindex $B4D6-JQ?t(B@code{PATH}
@cindex @code{PATH}$B!"4D6-JQ?t(B
@cindex $B4D6-JQ?t(B@code{HOME}
@cindex @code{HOME}$B!"4D6-JQ?t(B
@c   In all cases, the function's @var{program} argument specifies the
@c program to be run.  An error is signaled if the file is not found or
@c cannot be executed.  If the file name is relative, the variable
@c @code{exec-path} contains a list of directories to search.  Emacs
@c initializes @code{exec-path} when it starts up, based on the value of
@c the environment variable @code{PATH}.  The standard file name
@c constructs, @samp{~}, @samp{.}, and @samp{..}, are interpreted as usual
@c in @code{exec-path}, but environment variable substitutions
@c (@samp{$HOME}, etc.) are not recognized; use
@c @code{substitute-in-file-name} to perform them (@pxref{File Name
@c Expansion}).
$B$$$:$l$N>l9g$G$b!"4X?t$N0z?t(B@var{program}$B$O!"(B
$B<B9T$9$Y$-%W%m%0%i%`$r;XDj$7$^$9!#(B
$B$=$N%U%!%$%k$,$_$D$+$i$J$+$C$?$j<B9T$G$-$J$$$H!"(B
$B%(%i!<$rDLCN$7$^$9!#(B
$B%U%!%$%kL>$,AjBPL>$G$"$k$H!"(B
$BJQ?t(B@code{exec-path}$B$OC5:w$9$Y$-%G%#%l%/%H%j$N%j%9%H$rJ];}$7$F$$$^$9!#(B
Emacs$B$O5/F0;~$K4D6-JQ?t(B@code{PATH}$B$NCM$K4p$E$$$F(B@code{exec-path}$B$r(B
$B=i4|2=$7$^$9!#(B
@samp{~}$B!"(B@samp{.}$B!"(B@samp{..}$B$N%U%!%$%kL>$NI8=`E*$J=q$-J}$O!"(B
@code{exec-path}$B$G$bIaDL$I$*$j$K2r<a$5$l$^$9$,!"(B
$B!J(B@samp{$HOME}$B$J$I$N!K4D6-JQ?t$NCV49$OG'<1$7$^$;$s!#(B
$B$=$l$K$O(B@code{substitute-in-file-name}$B$r;H$$$^$9(B
$B!J(B@pxref{File Name Expansion}$B!K!#(B

@c   Each of the subprocess-creating functions has a @var{buffer-or-name}
@c argument which specifies where the standard output from the program will
@c go.  It should be a buffer or a buffer name; if it is a buffer name,
@c that will create the buffer if it does not already exist.  It can also
@c be @code{nil}, which says to discard the output unless a filter function
@c handles it.  (@xref{Filter Functions}, and @ref{Read and Print}.)
@c Normally, you should avoid having multiple processes send output to the
@c same buffer because their output would be intermixed randomly.
$B%5%V%W%m%;%9$r:n@.$9$k3F4X?t$K$O!"(B
$B%W%m%0%i%`$NI8=`=PNO$N<u$1<h$j>l=j$r;XDj$9$k(B
$B0z?t(B@var{buffer-or-name}$B$,$"$j$^$9!#(B
$B$3$l$O%P%C%U%!$+%P%C%U%!L>$G$"$kI,MW$,$"$j$^$9!#(B
$B%P%C%U%!L>$G$"$k$H!"$=$N%P%C%U%!$,4{B8$G$J$1$l$P?7$?$K:n@.$7$^$9!#(B
@code{nil}$B$G$b$+$^$$$^$;$s$,!"$=$N>l9g!"(B
$B%U%#%k%?4X?t$G=hM}$7$J$$8B$j=PNO$rGK4~$7$^$9!#(B
$B!J(B@ref{Filter Functions}$B$H(B@pxref{Read and Print}$B!K!#(B
$BDL>o!"J#?t$N%W%m%;%9$N=PNO$rF1$8%P%C%U%!$X$OAw$i$J$$$h$&$K$7$^$9!#(B
$B$=$l$i$N=PNO$,$G$?$i$a$K:.$6$C$F$7$^$&$+$i$G$9!#(B

@c @cindex program arguments
@cindex $B%W%m%0%i%`$N0z?t(B
@cindex $B0z?t!"%W%m%0%i%`(B
@c   All three of the subprocess-creating functions have a @code{&rest}
@c argument, @var{args}.  The @var{args} must all be strings, and they are
@c supplied to @var{program} as separate command line arguments.  Wildcard
@c characters and other shell constructs have no special meanings in these
@c strings, since the whole strings are passed directly to the specified
@c program.
$B%5%V%W%m%;%9$r:n@.$9$k(B3$B$D$N4X?t$9$Y$F$K!"(B
@code{&rest}$B0z?t$G$"$k(B@var{args}$B$,$"$j$^$9!#(B
@var{args}$B$O$9$Y$F$,J8;zNs$G$"$kI,MW$,$"$j!"(B
$B$=$l$>$l$r6h@Z$C$F%3%^%s%I9T0z?t$H$7$F(B@var{program}$B$KM?$($i$l$^$9!#(B
$B0z?tA4BN$r;XDj$5$l$?%W%m%0%i%`$XD>@\EO$9$?$a!"(B
$B$3$l$i$N0z?t$G$O%o%$%k%I%+!<%IJ8;z$dB>$N%7%'%k9=J8$NFCJL$J0UL#$O$"$j$^$;$s!#(B

@c   @strong{Please note:} The argument @var{program} contains only the
@c name of the program; it may not contain any command-line arguments.  You
@c must use @var{args} to provide those.
@strong{$BCm0U(B}$B!'(B@code{ }$B0z?t(B@var{program}$B$K$O%W%m%0%i%`$NL>A0$@$1$r;XDj$7!"(B
$B%3%^%s%I9T0z?t$O$$$C$5$$;XDj$7$J$$!#(B
$B%3%^%s%I9T0z?t$O(B@var{args}$B$GM?$($k$3$H!#(B

@c   The subprocess gets its current directory from the value of
@c @code{default-directory} (@pxref{File Name Expansion}).
$B%5%V%W%m%;%9$N%+%l%s%H%G%#%l%/%H%j$O(B
@code{default-directory}$B$NCM$G7h$^$j$^$9!J(B@pxref{File Name Expansion}$B!K!#(B

@c @cindex environment variables, subprocesses
@cindex $B4D6-JQ?t!"%5%V%W%m%;%9(B
@cindex $B%5%V%W%m%;%9$N4D6-JQ?t(B
@c   The subprocess inherits its environment from Emacs, but you can
@c specify overrides for it with @code{process-environment}.  @xref{System
@c Environment}.
$B%5%V%W%m%;%9$O(BEmacs$B$+$i4D6-JQ?t$r7Q>5$7$^$9$,!"(B
$BM%@h$9$k$b$N$r(B@code{process-environment}$B$G;XDj$G$-$^$9!#(B
@xref{System Environment}$B!#(B

@defvar exec-directory 
@pindex movemail
@c The value of this variable is the name of a directory (a string) that
@c contains programs that come with GNU Emacs, programs intended for Emacs
@c to invoke.  The program @code{movemail} is an example of such a program;
@c Rmail uses it to fetch new mail from an inbox.
$B$3$NJQ?t$NCM$O!"(BEmaccs$B$,5/F0$9$k$3$H$r0U?^$7$?(B
GNU Emacs$B$H$H$b$KG[I[$5$l$?%W%m%0%i%`72$r<}$a$?%G%#%l%/%H%jL>(B
$B!JJ8;zNs!K$G$"$k!#(B
$B%W%m%0%i%`(B@code{movemail}$B$O$=$N$h$&$J%W%m%0%i%`$NNc$G$"$j!"(B
inbox$B$+$i?7$?$J%a%$%k$r<h$j=P$9$?$a$K(Brmail$B$,MxMQ$9$k!#(B
@end defvar

@defopt exec-path
@c The value of this variable is a list of directories to search for
@c programs to run in subprocesses.  Each element is either the name of a
@c directory (i.e., a string), or @code{nil}, which stands for the default
@c directory (which is the value of @code{default-directory}).
@c @cindex program directories
$B$3$NJQ?t$NCM$O!"%5%V%W%m%;%9$G<B9T$9$k%W%m%0%i%`$rC5:w$9$k(B
$B%G%#%l%/%H%j$N%j%9%H$G$"$k!#(B
$B3FMWAG$O%G%#%l%/%H%jL>!JJ8;zNs!K$G$"$k$+!"(B
$B%G%U%)%k%H%G%#%l%/%H%j!J$D$^$j(B@code{default-directory}$B$NCM!K(B
$B$r0UL#$9$k(B@code{nil}$B$G$"$k!#(B
@cindex $B%W%m%0%i%`$rC5$9%G%#%l%/%H%j(B

@c The value of @code{exec-path} is used by @code{call-process} and
@c @code{start-process} when the @var{program} argument is not an absolute
@c file name.
$B0z?t(B@var{program}$B$,@dBP%U%!%$%kL>$G$J$$$H!"(B
@code{call-process}$B$H(B@code{start-process}$B$O(B
@code{exec-path}$B$NCM$r;H$&!#(B
@end defopt

@node Shell Arguments
@c @section Shell Arguments
@section $B%7%'%k0z?t(B

@c   Lisp programs sometimes need to run a shell and give it a command
@c which contains file names that were specified by the user.  These
@c programs ought to be able to support any valid file name.  But the shell
@c gives special treatment to certain characters, and if these characters
@c occur in the file name, they will confuse the shell.  To handle these
@c characters, use the function @code{shell-quote-argument}:
Lisp$B%W%m%0%i%`$+$i!"(B
$B%f!<%6!<$,;XDj$7$?%U%!%$%kL>$r4^$s$@%3%^%s%I$r;XDj$7$F(B
$B%7%'%k$r<B9T$9$kI,MW$,$H$-$I$-$"$j$^$9!#(B
$B$3$l$i$N%W%m%0%i%`$G$O!"G$0U$N@5$7$$%U%!%$%kL>$r07$($kI,MW$,$"$j$^$9!#(B
$B$7$+$7!"%7%'%k$O!"FCDj$NJ8;z$,%U%!%$%kL>$H$7$F8=$l$k$HFCJL$K07$&$N$G!"(B
$B$=$N$h$&$JJ8;z$,%7%'%k$K:.Mp$r$b$?$i$7$^$9!#(B
$B$=$N$h$&$JJ8;z$r07$&$K$O!"4X?t(B@code{shell-quote-argument}$B$r;H$$$^$9!#(B

@defun shell-quote-argument argument
@c This function returns a string which represents, in shell syntax,
@c an argument whose actual contents are @var{argument}.  It should
@c work reliably to concatenate the return value into a shell command
@c and then pass it to a shell for execution.
$B$3$N4X?t$O!"(B@var{argument}$B$r<B:]$NFbMF$H$9$k(B
$B%7%'%k9=J8$GI=$7$?0z?t$rJ8;zNs$GJV$9!#(B
$B$3$NLa$jCM$r%7%'%k%3%^%s%I$KO"7k$7!"(B
$B<B9T$N$?$a$K%7%'%k$KEO$7$F$bLdBj$r@8$8$J$$$O$:$G$"$k!#(B

@c Precisely what this function does depends on your operating system.  The
@c function is designed to work with the usual shell syntax; if you use an
@c unusual shell, you will need to redefine this function.  On MS-DOS, the
@c function returns @var{argument} unchanged; while this is not really
@c correct, it is the best one can do, since the MS-DOS shell has no
@c quoting features.
$B$3$N4X?t$,9T$&$3$H$N>\:Y$OFI<T$N%*%Z%l!<%F%#%s%0%7%9%F%`$K0MB8$9$k!#(B
$B$3$N4X?t$ODL>o$N%7%'%k9=J8$K9g$&$h$&$K@_7W$7$F$"$k!#(B
$BHsI8=`$N%7%'%k$r;H$&>l9g$K$O!"$3$N4X?t$r:FDj5A$9$kI,MW$,$"$m$&!#(B
MS-DOS$B$G$O!"$3$N4X?t$O(B@var{argument}$B$rL5JQ99$GJV$9!#(B
MS-DOS$B$N%7%'%k$K$O%/%)!<%H$N5!G=$,$J$$$?$a!"(B
$B$3$l$OK\Ev$O@5$7$$$3$H$G$O$J$$$,:GNI$N$3$H$G$"$k!#(B

@example
@c ;; @r{This example shows the behavior on GNU and Unix systems.}
;; @r{$B$D$.$NNc$O(BGNU$B$H(BUNIX$B%7%9%F%`$N$U$k$^$$$G$"$k(B}
(shell-quote-argument "foo > bar")
     @result{} "foo\\ \\>\\ bar"
@end example

@c Here's an example of using @code{shell-quote-argument} to construct
@c a shell command:
$B%7%'%k%3%^%s%I$r:n$k(B@code{shell-quote-argument}$B$N;HMQNc$r$D$.$K<($9!#(B

@example
(concat "diff -c "
        (shell-quote-argument oldfile)
        " "
        (shell-quote-argument newfile))
@end example
@end defun

@node Synchronous Processes
@c @section Creating a Synchronous Process
@section $BF14|%W%m%;%9$N:n@.(B
@c @cindex synchronous subprocess
@cindex $BF14|%5%V%W%m%;%9(B
@cindex $B%5%V%W%m%;%9!"F14|(B

@c   After a @dfn{synchronous process} is created, Emacs waits for the
@c process to terminate before continuing.  Starting Dired is an example of
@c this: it runs @code{ls} in a synchronous process, then modifies the
@c output slightly.  Because the process is synchronous, the entire
@c directory listing arrives in the buffer before Emacs tries to do
@c anything with it.
@dfn{$BF14|%W%m%;%9(B}$B!J(Bsynchronous process$B!K$r:n@.$9$k$H!"(B
Emacs$B$O<B9T$rB39T$9$k$^$($K$=$N%W%m%;%9$,=*N;$9$k$N$rBT$A$^$9!#(B
dired$B$O$=$NNc$G$9!#(B
@code{ls}$B$rF14|%W%m%;%9$G<B9T$7!"$=$N=PNO$r>/!9=$@5$7$^$9!#(B
$B%W%m%;%9$OF14|$J$N$G!"(BEmacs$B$,$J$K$+$r9T$*$&$H$9$k$^$($K(B
$B%G%#%l%/%H%j0lMwA4It$,%P%C%U%!$KFO$-$^$9!#(B

@c   While Emacs waits for the synchronous subprocess to terminate, the
@c user can quit by typing @kbd{C-g}.  The first @kbd{C-g} tries to kill
@c the subprocess with a @code{SIGINT} signal; but it waits until the
@c subprocess actually terminates before quitting.  If during that time the
@c user types another @kbd{C-g}, that kills the subprocess instantly with
@c @code{SIGKILL} and quits immediately.  @xref{Quitting}.
Emacs$B$OF14|%5%V%W%m%;%9$N=*N;$rBT$A$^$9$,!"(B
$B%f!<%6!<$O(B@kbd{C-g}$B$HBG$C$FCfCG$G$-$^$9!#(B
@kbd{C-g}$B$O$^$:%7%0%J%k(B@code{SIGINT}$B$G%5%V%W%m%;%9$r%-%k$7$h$&$H$7$^$9$,!"(B
$BCfCG$r40N;$9$k$^$($K%5%V%W%m%;%9$,=*N;$9$k$N$rBT$A$^$9!#(B
$B$=$N4|4V$K%f!<%6!<$,$5$i$K(B@kbd{C-g}$B$rBG$D$H!"(B
@code{SIGKILL}$B$G%5%V%W%m%;%9$rB(:B$K%-%k$7!"$?$@$A$KCfCG$r40N;$7$^$9!#(B
@xref{Quitting}$B!#(B

@c   The synchronous subprocess functions return an indication of how the
@c process terminated.
$BF14|%5%V%W%m%;%9:n@.4X?t$O!"(B
$B$=$N%W%m%;%9$,$I$N$h$&$K=*N;$7$?$+$rI=$9$b$N$rJV$7$^$9!#(B

@c   The output from a synchronous subprocess is generally decoded using a
@c coding system, much like text read from a file.  The input sent to a
@c subprocess by @code{call-process-region} is encoded using a coding
@c system, much like text written into a file.  @xref{Coding Systems}.
$BF14|%5%V%W%m%;%9$+$i$N=PNO$O!"%U%!%$%k$+$iFI$`%F%-%9%H$HF1MM$K!"(B
$B%3!<%G%#%s%0%7%9%F%`$rMQ$$$F0lHL$K$OI|9f2=$7$^$9!#(B
@code{call-process-region}$B$,%5%V%W%m%;%9$XAw$kF~NO$O!"(B
$B%U%!%$%k$X=q$/%F%-%9%H$HF1MM$K!"(B
$B%3!<%G%#%s%0%7%9%F%`$rMQ$$$FId9f2=$7$^$9!#(B
@xref{Coding Systems}$B!#(B

@defun call-process program &optional infile destination display &rest args
@c This function calls @var{program} in a separate process and waits for
@c it to finish.
$B$3$N4X?t$O!"JL$N%W%m%;%9$G(B@var{program}$B$r8F$S=P$7!"(B
$B$=$l$,=*N;$9$k$N$rBT$D!#(B

@c The standard input for the process comes from file @var{infile} if
@c @var{infile} is not @code{nil}, and from @file{/dev/null} otherwise.
@c The argument @var{destination} says where to put the process output.
@c Here are the possibilities:
@var{infile}$B$,(B@code{nil}$B$G$J$1$l$P(B
$B%W%m%;%9$X$NI8=`F~NO$O(B@var{infile}$B$G$"$k$,!"(B
$B$5$b$J$1$l$P(B@file{/dev/null}$B$G$"$k!#(B
$B0z?t(B@var{destination}$B$G%W%m%;%9$N=PNO@h$r$D$.$N$h$&$K;XDj$9$k!#(B

@table @asis
@c @item a buffer
@item $B%P%C%U%!(B
@c Insert the output in that buffer, before point.  This includes both the
@c standard output stream and the standard error stream of the process.
$B$3$N%P%C%U%!$N%]%$%s%H$N$^$($K=PNO$rA^F~$9$k!#(B
$B$3$l$K$O%W%m%;%9$NI8=`=PNO$HI8=`%(%i!<$NN><T$r4^$`!#(B

@c @item a string
@item $BJ8;zNs(B
@c Insert the output in a buffer with that name, before point.
$BJ8;zNs$G;XDj$7$?L>A0$N%P%C%U%!$N%]%$%s%H$N$^$($K=PNO$rA^F~$9$k!#(B

@item @code{t}
@c Insert the output in the current buffer, before point.
$B%+%l%s%H%P%C%U%!$N%]%$%s%H$N$^$($K=PNO$rA^F~$9$k!#(B

@item @code{nil}
@c Discard the output.
$B=PNO$rGK4~$9$k!#(B

@item 0
@c Discard the output, and return immediately without waiting
@c for the subprocess to finish.
$B=PNO$rGK4~$7!"%5%V%W%m%;%9$N=*N;$rBT$?$:$K$?$@$A$KLa$k!#(B

@c In this case, the process is not truly synchronous, since it can run in
@c parallel with Emacs; but you can think of it as synchronous in that
@c Emacs is essentially finished with the subprocess as soon as this
@c function returns.
$B$3$N>l9g!"$3$N%W%m%;%9$O(BEmacs$B$HJB9T$7$FF0:n$9$k$N$G??$N%5%V%W%m%;%9$G$O$J$$!#(B
$B$7$+$7!"$3$N4X?t$+$iLa$k$H(BEmacs$B$O%5%V%W%m%;%9$N=hM}$rK\<AE*$K$O=*$($?$H(B
$B$$$&0UL#$GF14|%W%m%;%9$H9M$($k$3$H$,$G$-$k!#(B

@item @code{(@var{real-destination} @var{error-destination})}
@c Keep the standard output stream separate from the standard error stream;
@c deal with the ordinary output as specified by @var{real-destination},
@c and dispose of the error output according to @var{error-destination}.
@c If @var{error-destination} is @code{nil}, that means to discard the
@c error output, @code{t} means mix it with the ordinary output, and a
@c string specifies a file name to redirect error output into.
$BI8=`=PNO$HI8=`%(%i!<$rJ,N%$7!"(B
@var{real-destination}$B$N;XDj$K=>$C$FDL>o$N=PNO$r07$$!"(B
@var{error-destination}$B$K=>$C$F%(%i!<=PNO$r=hM}$9$k!#(B
@var{error-destination}$B$,(B@code{nil}$B$G$"$k$H%(%i!<=PNO$rGK4~$7!"(B
@code{t}$B$G$"$k$HDL>o$N=PNO$K:.$<!"(B
$BJ8;zNs$G$"$k$H$=$NL>A0$N%U%!%$%k$K%(%i!<=PNO$r?6$j8~$1$k!#(B

@c You can't directly specify a buffer to put the error output in; that is
@c too difficult to implement.  But you can achieve this result by sending
@c the error output to a temporary file and then inserting the file into a
@c buffer.
$B%(%i!<=PNO$rF~$l$k%P%C%U%!$rD>@\$K;XDj$9$k$3$H$O$G$-$J$$!#(B
$B$=$l$r<BAu$9$k$N$OFq$7$9$.$k!#(B
$B$7$+$7!"%(%i!<=PNO$r0l;~%U%!%$%k$XAw$C$F$+$i(B
$B$=$N%U%!%$%k$r%P%C%U%!$KA^F~$9$l$P!"F1$88z2L$rF@$i$l$k!#(B
@end table

@c If @var{display} is non-@code{nil}, then @code{call-process} redisplays
@c the buffer as output is inserted.  (However, if the coding system chosen
@c for decoding output is @code{undecided}, meaning deduce the encoding
@c from the actual data, then redisplay sometimes cannot continue once
@c non-@sc{ASCII} characters are encountered.  There are fundamental
@c reasons why it is hard to fix this.)  Otherwise the function
@c @code{call-process} does no redisplay, and the results become visible on
@c the screen only when Emacs redisplays that buffer in the normal course
@c of events.
@var{display}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B@code{call-process}$B$O!"(B
$B=PNO$,A^F~$5$l$k$H%P%C%U%!$r:FI=<($9$k!#(B
$B!J$7$+$7!"%3!<%G%#%s%0%7%9%F%`$H$7$F<B:]$N%G!<%?$+$i(B
$B%3!<%G%#%s%0%7%9%F%`$r?dDj$9$k(B@code{undecided}$B$r;XDj$7$F$$$k$H!"(B
$BHs(B@sc{ASCII}$BJ8;z$K=P2q$&$H:FI=<($r7QB3$G$-$J$$>l9g$b$"$k!#(B
$B$3$l$r=$@5$9$k$N$,:$Fq$G$"$k:,K\E*$JM}M3$,$"$k!#!K(B
$B$5$b$J$1$l$P!"4X?t(B@code{call-process}$B$O:FI=<($7$J$$$N$G!"(B
Emacs$B$,DL>o$N2aDx$G$=$N%P%C%U%!$r:FI=<($9$k$^$G$O!"(B
$B%9%/%j!<%s>e$G7k2L$O8+$($J$$!#(B

@c The remaining arguments, @var{args}, are strings that specify command
@c line arguments for the program.
$B;D$j$N0z?t(B@var{args}$B$O!"%W%m%0%i%`$KBP$9$k(B
$B%3%^%s%I9T0z?t$r;XDj$9$kJ8;zNs$G$"$k!#(B

@c The value returned by @code{call-process} (unless you told it not to
@c wait) indicates the reason for process termination.  A number gives the
@c exit status of the subprocess; 0 means success, and any other value
@c means failure.  If the process terminated with a signal,
@c @code{call-process} returns a string describing the signal.
$B!JBT$?$J$$$h$&$K;X<($7$J$$8B$j!K(B@code{call-process}$B$,JV$9CM$O!"(B
$B%W%m%;%9$N=*N;M}M3$rI=$9!#(B
$B?t$G%5%V%W%m%;%9$N=*N;>uBV$rI=$7!"(B
0$B$O@.8y!"$=$l0J30$NCM$O<:GT$r0UL#$9$k!#(B
$B%W%m%;%9$,%7%0%J%k$G=*N;$9$k$H!"(B
@code{call-process}$B$O%7%0%J%k$r5-=R$9$kJ8;zNs$rJV$9!#(B

@c In the examples below, the buffer @samp{foo} is current.
$B$D$.$NNc$G$O!"%P%C%U%!(B@samp{foo}$B$,%+%l%s%H$G$"$k!#(B

@smallexample
@group
(call-process "pwd" nil t)
     @result{} nil

---------- Buffer: foo ----------
/usr/user/lewis/manual
---------- Buffer: foo ----------
@end group

@group
(call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
     @result{} nil

---------- Buffer: bar ----------
lewis:5LTsHm66CSWKg:398:21:Bil Lewis:/user/lewis:/bin/csh

---------- Buffer: bar ----------
@end group
@end smallexample

@c Here is a good example of the use of @code{call-process}, which used to
@c be found in the definition of @code{insert-directory}:
@code{insert-directory}$B$NDj5A$K$"$k(B@code{call-process}$B$N(B
$B$h$$;HMQNc$r$D$.$K<($9!#(B

@smallexample
@group
(call-process insert-directory-program nil t nil @var{switches}
              (if full-directory-p
                  (concat (file-name-as-directory file) ".")
                file))
@end group
@end smallexample
@end defun

@defun call-process-region start end program &optional delete destination display &rest args
@c This function sends the text between @var{start} to @var{end} as
@c standard input to a process running @var{program}.  It deletes the text
@c sent if @var{delete} is non-@code{nil}; this is useful when
@c @var{destination} is @code{t}, to insert the output in the current
@c buffer in place of the input.
$B$3$N4X?t$O!"(B@var{program}$B$rF0$+$9%W%m%;%9$NI8=`F~NO$H$7$F(B
@var{start}$B$H(B@var{end}$B$N$"$$$@$N%F%-%9%H$rAw$k!#(B
@var{delete}$B$,(B@code{nil}$B0J30$G$"$k$H!"Aw$C$?%F%-%9%H$r:o=|$9$k!#(B
$B$3$l$O!"%+%l%s%H%P%C%U%!$KAw$C$?F~NO$N$+$o$j$K=PNO$rA^F~$9$k$3$H$r(B
$B0UL#$9$k(B@var{destination}$B$,(B@code{t}$B$G$"$k$H$-$KM-MQ$G$"$k!#(B

@c The arguments @var{destination} and @var{display} control what to do
@c with the output from the subprocess, and whether to update the display
@c as it comes in.  For details, see the description of
@c @code{call-process}, above.  If @var{destination} is the integer 0,
@c @code{call-process-region} discards the output and returns @code{nil}
@c immediately, without waiting for the subprocess to finish.
$B0z?t(B@var{destination}$B$H(B@var{display}$B$O!"(B
$B%5%V%W%m%;%9$+$i$N=PNO$r$I$N$h$&$K07$$!"(B
$B=PNO$+E~Ce$9$k$?$S$KI=<($r99?7$9$k$+$I$&$+$r@)8f$9$k!#(B
$B>\$7$/$O!">e5-$N(B@code{call-process}$B$N5-=R$r;2>H!#(B
@var{destination}$B$,@0?t(B0$B$G$"$k$H!"(B
@code{call-process-region}$B$O!"%5%V%W%m%;%9$N=*N;$rBT$?$:$K(B
$B=PNO$rGK4~$7$F$?$@$A$K(B@code{nil}$B$rJV$9!#(B

@c The remaining arguments, @var{args}, are strings that specify command
@c line arguments for the program.
$B;D$j$N0z?t(B@var{args}$B$O!"%W%m%0%i%`$KBP$9$k(B
$B%3%^%s%I9T0z?t$r;XDj$9$kJ8;zNs$G$"$k!#(B

@c The return value of @code{call-process-region} is just like that of
@c @code{call-process}: @code{nil} if you told it to return without
@c waiting; otherwise, a number or string which indicates how the
@c subprocess terminated.
@code{call-process-region}$B$NLa$jCM$O(B@code{call-process}$B$HF1MM$G$"$j!"(B
$BBT$?$:$KLa$k$h$&$K;X<($9$k$H(B@code{nil}$B$G$"$j!"(B
$B$5$b$J$1$l$P%5%V%W%m%;%9$N=*N;>uBV$rI=$9?t$+J8;zNs$G$"$k!#(B

@c In the following example, we use @code{call-process-region} to run the
@c @code{cat} utility, with standard input being the first five characters
@c in buffer @samp{foo} (the word @samp{input}).  @code{cat} copies its
@c standard input into its standard output.  Since the argument
@c @var{destination} is @code{t}, this output is inserted in the current
@c buffer.
$B$D$.$NNc$G$O!"(B
$B%P%C%U%!(B@samp{foo}$B$N;O$a$N(B5$BJ8;z!JC18l(B@samp{input}$B!K$rI8=`F~NO$H$7$F(B
$B%f!<%F%#%j%F%#(B@code{cat}$B$r<B9T$9$k$?$a$K(B@code{call-process-region}$B$r;H$&!#(B
@code{cat}$B$O!"I8=`F~NO$rI8=`=PNO$X%3%T!<$9$k!#(B
$B0z?t(B@var{destination}$B$,(B@code{t}$B$G$"$k$N$G!"(B
$B=PNO$O%+%l%s%H%P%C%U%!$KA^F~$5$l$k!#(B

@smallexample
@group
---------- Buffer: foo ----------
input@point{}
---------- Buffer: foo ----------
@end group

@group
(call-process-region 1 6 "cat" nil t)
     @result{} nil

---------- Buffer: foo ----------
inputinput@point{}
---------- Buffer: foo ----------
@end group
@end smallexample

@c   The @code{shell-command-on-region} command uses
@c @code{call-process-region} like this:
$B%3%^%s%I(B@code{shell-command-on-region}$B$O!"(B
$B$D$.$N$h$&$K(B@code{call-process-region}$B$r;H$&!#(B

@smallexample
@group
(call-process-region 
 start end         
@c  shell-file-name      ; @r{Name of program.}
@c  nil                  ; @r{Do not delete region.}
@c  buffer               ; @r{Send output to @code{buffer}.}
@c  nil                  ; @r{No redisplay during output.}
@c  "-c" command)        ; @r{Arguments for the shell.}
 shell-file-name      ; @r{$B%W%m%0%i%`$NL>A0(B}
 nil                  ; @r{$B%j!<%8%g%s$r:o=|$7$J$$(B}
 buffer               ; @r{$B=PNO$O(B@code{buffer}$B$XF~$l$k(B}
 nil                  ; @r{$B=PNOCf$O:FI=<($7$J$$(B}
 "-c" command)        ; @r{$B%7%'%k$KBP$9$k0z?t(B}
@end group
@end smallexample
@end defun

@defun shell-command-to-string command
@tindex shell-command-to-string
@c This function executes @var{command} (a string) as a shell command,
@c then returns the command's output as a string.
$B$3$N4X?t$O!"%7%'%k%3%^%s%I$H$7$F(B@var{command}$B!JJ8;zNs!K$r<B9T$7!"(B
$B%3%^%s%I$N=PNO$rJ8;zNs$H$7$FJV$9!#(B
@end defun

@node Asynchronous Processes
@c @section Creating an Asynchronous Process
@section $BHsF14|%W%m%;%9$N:n@.(B
@c @cindex asynchronous subprocess
@cindex $BHsF14|%W%m%;%9(B
@cindex $B%W%m%;%9!"HsF14|(B

@c   After an @dfn{asynchronous process} is created, Emacs and the subprocess
@c both continue running immediately.  The process thereafter runs
@c in parallel with Emacs, and the two can communicate with each other
@c using the functions described in following sections.  However,
@c communication is only partially asynchronous: Emacs sends data to the
@c process only when certain functions are called, and Emacs accepts data
@c from the process only when Emacs is waiting for input or for a time
@c delay.
@dfn{$BHsF14|%W%m%;%9(B}$B$r:n@.$9$k$H!"(BEmacs$B$H%5%V%W%m%;%9$NN><T$O(B
$B$?$@$A$KF0:n$r7QB3$7$^$9!#(B
$B$=$7$F%W%m%;%9$O(BEmacs$B$HJB9T$KF0:n$7!"(B
$BN><T$O0J2<$N@a$K=R$Y$k4X?t$rMQ$$$F8_$$$KDL?.$G$-$^$9!#(B
$B$7$+$7!"DL?.$OItJ,E*$KHsF14|$G$9!#(B
$BFCDj$N4X?t$r8F$S=P$7$?$H$-$K$@$1(BEmacs$B$O%W%m%;%9$X%G!<%?$rAw$j!"(B
Emacs$B$,F~NOBT$A$+;~4VBT$A$r$7$F$$$k$H$-$K$@$1(B
$B%W%m%;%9$+$i$N=PNO$r<u$1<h$l$^$9!#(B

@c   Here we describe how to create an asynchronous process.
$B$3$3$G$O!"HsF14|%W%m%;%9$N:n@.J}K!$K$D$$$F=R$Y$^$9!#(B

@defun start-process name buffer-or-name program &rest args
@c This function creates a new asynchronous subprocess and starts the
@c program @var{program} running in it.  It returns a process object that
@c stands for the new subprocess in Lisp.  The argument @var{name}
@c specifies the name for the process object; if a process with this name
@c already exists, then @var{name} is modified (by appending @samp{<1>},
@c etc.) to be unique.  The buffer @var{buffer-or-name} is the buffer to
@c associate with the process.
$B$3$N4X?t$O!"?7$?$JHsF14|%5%V%W%m%;%9$r:n@.$7!"(B
$B$=$N%W%m%;%9$G%W%m%0%i%`(B@var{program}$B$rAv$i$;$k!#(B
Lisp$B$K$*$$$F?7$?$J%5%V%W%m%;%9$rI=$9%W%m%;%9%*%V%8%'%/%H$rJV$9!#(B
$B0z?t(B@var{name}$B$O%W%m%;%9%*%V%8%'%/%H$NL>A0$r;XDj$9$k!#(B
$B$=$NL>A0$N%W%m%;%9$,$9$G$KB8:_$9$k$H!"(B
$BL>A0$r0l0U$K$9$k$?$a$K!J(B@samp{<1>}$B$J$I$rIU2C$7$F!K(B@var{name}$B$r=$@5$9$k!#(B
$B%P%C%U%!(B@var{buffer-or-name}$B$O!"$=$N%W%m%;%9$KBP1~IU$1$k%P%C%U%!$G$"$k!#(B

@c The remaining arguments, @var{args}, are strings that specify command
@c line arguments for the program.
$B;D$j$N0z?t(B@var{args}$B$O!"%W%m%0%i%`$KBP$9$k(B
$B%3%^%s%I9T0z?t$r;XDj$9$kJ8;zNs$G$"$k!#(B

@c In the example below, the first process is started and runs (rather,
@c sleeps) for 100 seconds.  Meanwhile, the second process is started, and
@c given the name @samp{my-process<1>} for the sake of uniqueness.  It
@c inserts the directory listing at the end of the buffer @samp{foo},
@c before the first process finishes.  Then it finishes, and a message to
@c that effect is inserted in the buffer.  Much later, the first process
@c finishes, and another message is inserted in the buffer for it.
$B$D$.$NNc$G$O!":G=i$N%W%m%;%9$OF0$-;O$a$k$H(B
100$BIC4V!J5Y;_$G$O$J$/!KF0:n$9$k!#(B
$B$=$N$"$$$@$K(B2$BHVL\$N%W%m%;%9$rF0$+$7;O$a$k$H!"(B
$B0l0U$G$"$k$?$a$K$=$l$K$OL>A0(B@samp{my-process<1>}$B$,M?$($i$l$k!#(B
2$BHVL\$N%W%m%;%9$O!":G=i$N%W%m%;%9$,=*N;$9$k$^$($K(B
$B%P%C%U%!(B@samp{foo}$B$K%G%#%l%/%H%j0lMw$rA^F~$9$k!#(B
2$BHVL\$N%W%m%;%9$,=*N;$9$k$H$=$l$rI=$9%a%C%;!<%8$,%P%C%U%!$KA^F~$5$l$k!#(B
$B$7$P$i$/$7$F:G=i$N%W%m%;%9$,=*N;$9$k$H!"(B
$BJL$N%a%C%;!<%8$,%P%C%U%!$KA^F~$5$l$k!#(B

@smallexample
@group
(start-process "my-process" "foo" "sleep" "100")
     @result{} #<process my-process>
@end group

@group
(start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
     @result{} #<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 ----------
@end group
@end smallexample
@end defun

@defun start-process-shell-command name buffer-or-name command &rest command-args
@c This function is like @code{start-process} except that it uses a shell
@c to execute the specified command.  The argument @var{command} is a shell
@c command name, and @var{command-args} are the arguments for the shell
@c command.  The variable @code{shell-file-name} specifies which shell to
@c use.
$B$3$N4X?t$O(B@code{start-process}$B$HF1MM$G$"$k$,!"(B
$B;XDj$7$?%3%^%s%I$r<B9T$9$k$?$a$K%7%'%k$rMQ$$$kE@$,0[$J$k!#(B
$B0z?t(B@var{command}$B$O%7%'%k%3%^%s%I$NL>A0$G$"$j!"(B
@var{command-args}$B$O$=$N%7%'%k%3%^%s%I$KBP$9$k0z?t$G$"$k!#(B
$BJQ?t(B@code{shell-file-name}$B$O!";HMQ$9$k%7%'%k$r;XDj$9$k!#(B

@c The point of running a program through the shell, rather than directly
@c with @code{start-process}, is so that you can employ shell features such
@c as wildcards in the arguments.  It follows that if you include an
@c arbitrary user-specified filename in the command, you should quote it
@c with @code{shell-quote-argument} first, so that any special shell
@c characters in the file name do @emph{not} have their special shell
@c meanings.  @xref{Shell Arguments}.
@code{start-process}$B$GD>@\$K$G$O$J$/(B
$B%7%'%k$r2p$7$F%W%m%0%i%`$r<B9T$9$k$H!"(B
$B0z?t$N%o%$%k%I%+!<%I$J$I$N%7%'%k$N5!G=$rMxMQ$G$-$k!#(B
$B$D$^$j!"%f!<%6!<;XDj$NG$0U$N%U%!%$%kL>$r%3%^%s%I$KF~$l$k>l9g$K$O!"(B
$B$^$($b$C$F(B@code{shell-quote-argument}$B$G%/%)!<%H$7!"(B
$B%U%!%$%kL>Fb$N%7%'%k$NFCJL$JJ8;z$,(B
$B$=$N$h$&$JFCJL$J0UL#$r;}$?(B@emph{$B$J$$(B}$B$h$&$K$9$k!#(B
@pxref{Shell Arguments}$B!#(B
@end defun

@defvar process-connection-type
@c @cindex pipes
@cindex $B%Q%$%W(B
@c @cindex @sc{pty}s
@cindex $B5?;wC<Kv(B@sc{pty}
@c This variable controls the type of device used to communicate with
@c asynchronous subprocesses.  If it is non-@code{nil}, then @sc{pty}s are
@c used, when available.  Otherwise, pipes are used.
$B$3$NJQ?t$O!"HsF14|%5%V%W%m%;%9$H$NDL?.$KMQ$$$kAuCV$N7?$r@)8f$9$k!#(B
$B$3$l$,(B@code{nil}$B0J30$G$"$k$H5?;wC<Kv(B@sc{pty}$B$rMxMQ$G$-$k>l9g$K$O$=$l$rMQ$k!#(B
$B$5$b$J$1$l$P%Q%$%W$rMQ$$$k!#(B

@c @sc{pty}s are usually preferable for processes visible to the user, as
@c in Shell mode, because they allow job control (@kbd{C-c}, @kbd{C-z},
@c etc.) to work between the process and its children, whereas pipes do
@c not.  For subprocesses used for internal purposes by programs, it is
@c often better to use a pipe, because they are more efficient.  In
@c addition, the total number of @sc{pty}s is limited on many systems and
@c it is good not to waste them.
$B%7%'%k!J(Bshell$B!K%b!<%I$J$I$N%f!<%6!<$K8+$($k%W%m%;%98~$1$K$O!"(B
$B%Q%$%W$G$OIT2DG=$J%W%m%;%9$H$=$N;R%W%m%;%9$H$N$"$$$@$G(B
$B%8%g%V@)8f!J(B@kbd{C-c}$B!"(B@kbd{C-z}$B$J$I!K$r5v$9$N$G(B
$B5?;wC<Kv(B@sc{pty}$B$,K>$^$7$$!#(B
$B%W%m%0%i%`$NFbItL\E*8~$1$K;H$o$l$k%5%V%W%m%;%9$G$O!"(B
$B8zN(E*$J%Q%$%W$rMQ$$$k$[$&$,$h$$!#(B
$B$^$?!"B?$/$N%7%9%F%`$G$O5?;wC<Kv(B@sc{pty}$B$NAm?t$K$O@)Ls$,$"$j!"(B
$B$=$l$i$rO2Hq$7$J$$$[$&$,$h$$!#(B

@c The value @code{process-connection-type} is used when
@c @code{start-process} is called.  So you can specify how to communicate
@c with one subprocess by binding the variable around the call to
@c @code{start-process}.
@code{process-connection-type}$B$NCM$O(B
@code{start-process}$B$r8F$S=P$7$?$H$-$K;H$o$l$k!#(B
$B$7$?$,$C$F!"(B@code{start-process}$B$N8F$S=P$7$N<~$j$G$3$NJQ?t$rB+G{$9$k$3$H$G!"(B
1$B$D$N%5%V%W%m%;%9$KBP$9$kDL?.J}K!$r;XDj$G$-$k!#(B

@smallexample
@group
@c (let ((process-connection-type nil))  ; @r{Use a pipe.}
(let ((process-connection-type nil))  ; @r{$B%Q%$%W$r;H$&(B}
  (start-process @dots{}))
@end group
@end smallexample

@c To determine whether a given subprocess actually got a pipe or a
@c @sc{pty}, use the function @code{process-tty-name} (@pxref{Process
@c Information}).
$B%5%V%W%m%;%9$,<B:]$K$O%Q%$%W$+5?;wC<Kv(B@sc{pty}$B$N$I$A$i$r(B
$B;H$C$F$$$k$+$rD4$Y$k$K$O!"4X?t(B@code{process-tty-name}$B$r;H$&(B
$B!J(B@pxref{Process Information}$B!K!#(B
@end defvar

@node Deleting Processes
@c @section Deleting Processes
@section $B%W%m%;%9$N:o=|(B
@c @cindex deleting processes
@cindex $B%W%m%;%9$N:o=|(B

@c   @dfn{Deleting a process} disconnects Emacs immediately from the
@c subprocess, and removes it from the list of active processes.  It sends
@c a signal to the subprocess to make the subprocess terminate, but this is
@c not guaranteed to happen immediately.  The process object itself
@c continues to exist as long as other Lisp objects point to it.  The
@c process mark continues to point to the same place as before (usually
@c into a buffer where output from the process was being inserted).
@dfn{$B%W%m%;%9$r:o=|$9$k(B}$B$H$O!"%5%V%W%m%;%9$+$i(BEmacs$B$r$?$@$A$K@Z$jN%$7!"(B
$B%5%V%W%m%;%9$r3h@-$J%W%m%;%9%j%9%H$+$i<h$j=|$/$3$H$G$9!#(B
$B%5%V%W%m%;%9$X%7%0%J%k$rAw$C$F%5%V%W%m%;%9$r=*N;$5$;$^$9$,!"(B
$B$?$@$A$K=*N;$9$k$H$OJ]>Z$5$l$^$;$s!#(B
$B%W%m%;%9%*%V%8%'%/%H$r;X$9(BLisp$B%*%V%8%'%/%H$,$"$k8B$j!"(B
$B%W%m%;%9%*%V%8%'%/%H$OB8:_$7B3$1$^$9!#(B
$B%W%m%;%9%^!<%/$O0JA0$HF1MM$KF1$8>l=j(B
$B!J%W%m%;%9$+$i$N=PNO$r%P%C%U%!$KA^F~$7$?2U=j!K$r;X$7B3$1$^$9!#(B

@c   You can delete a process explicitly at any time.  Processes are
@c deleted automatically after they terminate, but not necessarily right
@c away.  If you delete a terminated process explicitly before it is
@c deleted automatically, no harm results.
$B%W%m%;%9$O$$$D$G$bL@<(E*$K:o=|$G$-$^$9!#(B
$B%W%m%;%9$O=*N;8e$K<+F0E*$K:o=|$5$l$^$9$,!"(B
$B=*N;8e$?$@$A$K$G$O$"$j$^$;$s!#(B
$B=*N;$7$?%W%m%;%9$,<+F0E*$K:o=|$5$l$k$^$($KL@<(E*$K:o=|$7$F$bL532$G$9!#(B

@defopt delete-exited-processes
@c This variable controls automatic deletion of processes that have
@c terminated (due to calling @code{exit} or to a signal).  If it is
@c @code{nil}, then they continue to exist until the user runs
@c @code{list-processes}.  Otherwise, they are deleted immediately after
@c they exit.
$B$3$NJQ?t$O!"!J(B@code{exit}$B$r8F$S=P$9$+%7%0%J%k$N$?$a$K!K=*N;$7$?(B
$B%W%m%;%9$N<+F0:o=|$r@)8f$9$k!#(B
@code{nil}$B$G$"$k$H!"%f!<%6!<$,(B@code{list-processes}$B$r(B
$B<B9T$9$k$^$GB8:_$7B3$1$k!#(B
$B$5$b$J$1$l$P!"=*N;8e$K$?$@$A$K:o=|$9$k!#(B
@end defopt

@defun delete-process name
@c This function deletes the process associated with @var{name}, killing it
@c with a @code{SIGHUP} signal.  The argument @var{name} may be a process,
@c the name of a process, a buffer, or the name of a buffer.
$B$3$N4X?t$O!"(B@var{name}$B$KBP1~IU$1$i$l$?%W%m%;%9$r(B
$B%7%0%J%k(B@code{SIGHUP}$B$G%-%k$7:o=|$9$k!#(B
$B0z?t$O!"%W%m%;%9!"%W%m%;%9L>!"%P%C%U%!!"%P%C%U%!L>$N$$$:$l$+$G$"$k!#(B

@smallexample
@group
(delete-process "*shell*")
     @result{} nil
@end group
@end smallexample
@end defun

@defun process-kill-without-query process &optional do-query
@c This function specifies whether Emacs should query the user if
@c @var{process} is still running when Emacs is exited.  If @var{do-query}
@c is @code{nil}, the process will be deleted silently.
@c Otherwise, Emacs will query about killing it.
$B$3$N4X?t$O!"(BEmacs$B$r=*N;$9$k$H$-$K%W%m%;%9(B@var{process}$B$,F0:nCf$G$"$k$H!"(B
$B%f!<%6!<$KLd$$9g$o$;$k$+$I$&$+$r;XDj$9$k!#(B
@var{do-query}$B$,(B@code{nil}$B$G$"$k$H!"%W%m%;%9$rL[$C$F:o=|$9$k!#(B
$B$5$b$J$1$l$P!"(BEmacs$B$O%W%m%;%9$N%-%k$K4X$7$FLd$$9g$o$;$k!#(B

@c The value is @code{t} if the process was formerly set up to require
@c query, @code{nil} otherwise.  A newly-created process always requires
@c query.
$BLd$$9g$o$;$k$h$&$K$7$F$"$C$?%W%m%;%9$G$"$k$HLa$jCM$O(B@code{t}$B$G$"$j!"(B
$B$5$b$J$1$l$PLa$jCM$O(B@code{nil}$B$G$"$k!#(B
$B?7$?$K:n@.$5$l$?%W%m%;%9$O!"$D$M$KLd$$9g$o$;MQ$K$J$C$F$$$k!#(B

@smallexample
@group
(process-kill-without-query (get-process "shell"))
     @result{} t
@end group
@end smallexample
@end defun

@node Process Information
@c @section Process Information
@section $B%W%m%;%9>pJs(B

@c   Several functions return information about processes.
@c @code{list-processes} is provided for interactive use.
$B%W%m%;%9$K4X$9$k>pJs$rJV$94X?t$,$$$/$D$+$"$j$^$9!#(B
@code{list-processes}$B$OBPOCE*MxMQ$N$?$a$K$"$j$^$9!#(B

@c @deffn Command list-processes
@deffn $B%3%^%s%I(B list-processes
@c This command displays a listing of all living processes.  In addition,
@c it finally deletes any process whose status was @samp{Exited} or
@c @samp{Signaled}.  It returns @code{nil}.
$B$3$N%3%^%s%I$O!"3h@-$J$9$Y$F$N%W%m%;%9$N0lMw$rI=<($9$k!#(B
$B$5$i$K!"(B@samp{Exited}$B$d(B@samp{Signaled}$B$G$"$k>uBV$N(B
$B%W%m%;%9$r$9$Y$F:o=|$9$k!#(B
@code{nil}$B$rJV$9!#(B
@end deffn

@defun process-list
@c This function returns a list of all processes that have not been deleted.
$B$3$N4X?t$O!":o=|$5$l$F$$$J$$$9$Y$F$N%W%m%;%9$N%j%9%H$rJV$9!#(B

@smallexample
@group
(process-list)
     @result{} (#<process display-time> #<process shell>)
@end group
@end smallexample
@end defun

@defun get-process name
@c This function returns the process named @var{name}, or @code{nil} if
@c there is none.  An error is signaled if @var{name} is not a string.
$B$3$N4X?t$O(B@var{name}$B$H$$$&L>A0$N%W%m%;%9$rJV$9!#(B
$B$"$k$$$O!"$=$N$h$&$J%W%m%;%9$,$J$1$l$P(B@code{nil}$B$rJV$9!#(B
@var{name}$B$,J8;zNs$G$J$$$H%(%i!<$rDLCN$9$k!#(B

@smallexample
@group
(get-process "shell")
     @result{} #<process shell>
@end group
@end smallexample
@end defun

@defun process-command process
@c This function returns the command that was executed to start
@c @var{process}.  This is a list of strings, the first string being the
@c program executed and the rest of the strings being the arguments that
@c were given to the program.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$r;OF0$9$k$?$a$K<B9T$7$?%3%^%s%I$rJV$9!#(B
$B$3$l$OJ8;zNs$N%j%9%H$G$"$j!"(B
$B:G=i$NJ8;zNs$O<B9T$5$l$?%W%m%0%i%`!"(B
$B;D$j$NJ8;zNs$O$=$N%W%m%0%i%`$KM?$($?0z?t$G$"$k!#(B

@smallexample
@group
(process-command (get-process "shell"))
     @result{} ("/bin/csh" "-i")
@end group
@end smallexample
@end defun

@defun process-id process
@c This function returns the @sc{pid} of @var{process}.  This is an
@c integer that distinguishes the process @var{process} from all other
@c processes running on the same computer at the current time.  The
@c @sc{pid} of a process is chosen by the operating system kernel when the
@c process is started and remains constant as long as the process exists.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$N%W%m%;%9HV9f(B@sc{pid}$B$rJV$9!#(B
$B$3$l$OF1$87W;;5!>e$GF0$$$F$$$kB>$N$9$Y$F$N%W%m%;%9$H(B
$B%W%m%;%9(B@var{process}$B$r6hJL$9$k$?$a$N@0?t$G$"$k!#(B
$B%W%m%;%9$N(B@sc{pid}$B$O!"%W%m%;%9$r;OF0$7$?$H$-$K(B
$B%*%Z%l!<%F%#%s%0%7%9%F%`$N%+!<%M%k$,A*$S!"(B
$B%W%m%;%9$,=*N;$9$k$^$GJQ$o$i$J$$!#(B
@end defun

@defun process-name process
@c This function returns the name of @var{process}.
$B$3$N4X?t$O%W%m%;%9(B@var{process}$B$NL>A0$rJV$9!#(B
@end defun

@defun process-contact process
@tindex process-contact
@c This function returns @code{t} for an ordinary child process, and
@c @code{(@var{hostname} @var{service})} for a net connection
@c (@pxref{Network}).
$B$3$N4X?t$O!"DL>o$N;R%W%m%;%9$KBP$7$F$O(B@code{t}$B$rJV$7!"(B
$B%M%C%H%o!<%/@\B3$KBP$7$F$O(B@code{(@var{hostname} @var{service})}$B$rJV$9(B
$B!J(B@pxref{Network}$B!K!#(B
@end defun

@defun process-status process-name
@c This function returns the status of @var{process-name} as a symbol.
@c The argument @var{process-name} must be a process, a buffer, a
@c process name (string) or a buffer name (string).
$B$3$N4X?t$O!"(B@var{process-name}$B$N>uBV$r%7%s%\%k$H$7$FJV$9!#(B
$B0z?t(B@var{process-name}$B$O!"%W%m%;%9!"%P%C%U%!!"%W%m%;%9L>!JJ8;zNs!K!"(B
$B%P%C%U%!L>!JJ8;zNs!K$N$$$:$l$+$G$"$k$3$H!#(B

@c The possible values for an actual subprocess are:
$B<B:]$N%5%V%W%m%;%9$KBP$7$F2DG=$JCM$O$D$.$N$H$*$j!#(B

@table @code
@item run
@c for a process that is running.
$B<B9TCf$N%W%m%;%9$G$"$k!#(B
@item stop
@c for a process that is stopped but continuable.
$B0l;~Dd;_$7$F$$$k$,7QB32DG=$G$"$k!#(B
@item exit
@c for a process that has exited.
$B=*N;$7$?%W%m%;%9!#(B
@item signal
@c for a process that has received a fatal signal.
$BCWL?E*$J%7%0%J%k$r<u$1<h$C$?%W%m%;%9$G$"$k!#(B
@item open
@c for a network connection that is open.
$B%M%C%H%o!<%/@\B3$r3+$$$F$$$k!#(B
@item closed
@c for a network connection that is closed.  Once a connection
@c is closed, you cannot reopen it, though you might be able to open
@c a new connection to the same place.
$B%M%C%H%o!<%/@\B3$OJD$8$F$$$k!#(B
$B@\B3$r$$$C$?$sJD$8$k$H$=$l$r:FEY3+$/$3$H$O$G$-$J$$$,!"(B
$BF1$8@\B3@h$X?7$?$J@\B3$r3+$/$3$H$O$G$-$k!#(B
@item nil
@c if @var{process-name} is not the name of an existing process.
@var{process-name}$B$O4{B8%W%m%;%9$NL>A0$G$O$J$$!#(B
@end table

@smallexample
@group
(process-status "shell")
     @result{} run
@end group
@group
(process-status (get-buffer "*shell*"))
     @result{} run
@end group
@group
x
     @result{} #<process xx<1>>
(process-status x)
     @result{} exit
@end group
@end smallexample

@c For a network connection, @code{process-status} returns one of the symbols
@c @code{open} or @code{closed}.  The latter means that the other side
@c closed the connection, or Emacs did @code{delete-process}.
$B%M%C%H%o!<%/@\B3$G$O!"(B@code{process-status}$B$O(B
$B%7%s%\%k(B@code{open}$B$+(B@code{closed}$B$N$$$:$l$+$rJV$9!#(B
$B8e<T$O!"Aj<jB&$,@\B3$rJD$8$?$+(B
Emacs$B$,(B@code{delete-process}$B$r9T$C$?$3$H$rI=$9!#(B
@end defun

@defun process-exit-status process
@c This function returns the exit status of @var{process} or the signal
@c number that killed it.  (Use the result of @code{process-status} to
@c determine which of those it is.)  If @var{process} has not yet
@c terminated, the value is 0.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$N=*N;>uBV$+!"(B
$B%W%m%;%9$r%-%k$7$?%7%0%J%kHV9f$rJV$9!#(B
$B!J$I$A$i$G$"$k$+$rH=Dj$9$k$K$O!"(B@code{process-status}$B$N7k2L$rMQ$$$k!#!K(B
@var{process}$B$,=*N;$7$F$$$J$$$HCM$O(B0$B$G$"$k!#(B
@end defun

@defun process-tty-name process
@c This function returns the terminal name that @var{process} is using for
@c its communication with Emacs---or @code{nil} if it is using pipes
@c instead of a terminal (see @code{process-connection-type} in
@c @ref{Asynchronous Processes}).
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$,(BEmacs$B$H$NDL?.$KMQ$$$F$$$kC<KvL>$rJV$9!#(B
$B$"$k$$$O!"C<Kv$N$+$o$j$K%Q%$%W$rMQ$$$F$$$l$P(B@code{nil}$B$rJV$9(B
$B!J(B@ref{Asynchronous Processes}$B$N(B@code{process-connection-type}$B$r;2>H!K!#(B
@end defun

@defun process-coding-system process
@tindex process-coding-system
@c This function returns a cons cell describing the coding systems in use
@c for decoding output from @var{process} and for encoding input to
@c @var{process} (@pxref{Coding Systems}).  The value has this form:
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$+$i$N=PNO$r(B
$BI|9f2=$9$k$?$a$KMQ$$$F$$$k%3!<%G%#%s%0%7%9%F%`$H!"(B
@var{process}$B$X$NF~NO$rId9f2=$9$k$?$a$KMQ$$$F$$$k(B
$B%3!<%G%#%s%0%7%9%F%`$r5-=R$9$k%3%s%9%;%k$rJV$9!#(B

@example
(@var{coding-system-for-decoding} . @var{coding-system-for-encoding})
@end example
@end defun

@defun set-process-coding-system process decoding-system encoding-system
@tindex set-process-coding-system
@c This function specifies the coding systems to use for subsequent output
@c from and input to @var{process}.  It will use @var{decoding-system} to
@c decode subprocess output, and @var{encoding-system} to encode subprocess
@c input.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$+$i$N0J9_$N=PNO$*$h$SF~NO$KMQ$$$k(B
$B%3!<%G%#%s%0%7%9%F%`$r;XDj$9$k!#(B
$B%5%V%W%m%;%9$+$i=PNO$NI|9f2=$K$O(B@var{decoding-system}$B$r;H$$!"(B
$B%5%V%W%m%;%9$NF~NO$NId9f2=$K$O(B@var{encoding-system}$B$r;H$&!#(B
@end defun

@node Input to Processes
@c @section Sending Input to Processes
@section $B%W%m%;%9$XF~NO$rAw$k(B
@c @cindex process input
@cindex $B%W%m%;%9$NF~NO(B
@cindex $BF~NO!"%W%m%;%9(B

@c   Asynchronous subprocesses receive input when it is sent to them by
@c Emacs, which is done with the functions in this section.  You must
@c specify the process to send input to, and the input data to send.  The
@c data appears on the ``standard input'' of the subprocess.
$BK\@a$N4X?t$rMQ$$$F(BEmacs$B$,F~NO$rAw$k$H!"(B
$BHsF14|%W%m%;%9$OF~NO$r<u$1<h$j$^$9!#(B
$BF~NO$NAw@h$G$"$k%W%m%;%9$H!"Aw$k$Y$-F~NO%G!<%?$r;XDj$9$kI,MW$,$"$j$^$9!#(B
$B$=$N%G!<%?$O!"%5%V%W%m%;%9$N!XI8=`F~NO!Y$K8=$l$^$9!#(B

@c   Some operating systems have limited space for buffered input in a
@c @sc{pty}.  On these systems, Emacs sends an @sc{eof} periodically amidst
@c the other characters, to force them through.  For most programs,
@c these @sc{eof}s do no harm.
$B5?;wC<Kv(B@sc{pty}$B$N%P%C%U%!IU$-F~NO$NMFNL$K>e8B$,$"$k(B
$B%*%Z%l!<%F%#%s%0%7%9%F%`$b$"$j$^$9!#(B
$B$=$N$h$&$J%7%9%F%`$G$O!"(BEmacs$B$OB>$NJ8;z$K:.$<$FDj4|E*$K(B@sc{eof}$B$rAw$j!"(B
$BJ8;z$,N.$l$k$h$&$K6/@)$7$^$9!#(B
$B$[$H$s$I$N%W%m%0%i%`$G$O!"$3$N$h$&$J(B@sc{eof}$B$OL532$J$O$:$G$9!#(B

@c   Subprocess input is normally encoded using a coding system before the
@c subprocess receives it, much like text written into a file.  You can use
@c @code{set-process-coding-system} to specify which coding system to use
@c (@pxref{Process Information}).  Otherwise, the coding system comes from
@c @code{coding-system-for-write}, if that is non-@code{nil}; or else from
@c the defaulting mechanism (@pxref{Default Coding Systems}).
$B%U%!%$%k$K=q$-9~$`%F%-%9%H$HF1MM$K!"(B
$B%5%V%W%m%;%9$NF~NO$O!"%5%V%W%m%;%9$,$=$l$r<u$1<h$k$^$($K(B
$B%3!<%G%#%s%0%7%9%F%`$rMQ$$$FIaDL$OId9f2=$5$l$^$9!#(B
@code{set-process-coding-system}$B$G(B
$B;HMQ$9$k%3!<%G%#%s%0%7%9%F%`$r;XDj$G$-$^$9(B
$B!J(B@pxref{Process Information}$B!K!#(B
$B$5$b$J$1$l$P!"(B@code{coding-system-for-write}$B$,(B
@code{nil}$B0J30$G$"$l$P$3$l$r;H$$$^$9!#(B
$B$=$l0J30$G$O%G%U%)%k%H$N5!9=$G7h$^$k$b$N$r;H$$$^$9(B
$B!J(B@pxref{Default Coding Systems}$B!K!#(B

@defun process-send-string process-name string
@c This function sends @var{process-name} the contents of @var{string} as
@c standard input.  The argument @var{process-name} must be a process or
@c the name of a process.  If it is @code{nil}, the current buffer's
@c process is used.
$B$3$N4X?t$O!"J8;zNs(B@var{string}$B$NFbMF$r(B
$BI8=`F~NO$H$7$F%W%m%;%9(B@var{process-name}$B$KAw$k!#(B
$B0z?t(B@var{process-name}$B$O!"%W%m%;%9$+%W%m%;%9L>$G$"$k$3$H!#(B
$B$3$l$,(B@code{nil}$B$G$"$k$H!"%+%l%s%H%P%C%U%!$N%W%m%;%9$rMQ$$$k!#(B

@c   The function returns @code{nil}.
$B4X?t$O(B@code{nil}$B$rJV$9!#(B

@smallexample
@group
(process-send-string "shell<1>" "ls\n")
     @result{} nil
@end group


@group
---------- Buffer: *shell* ----------
...
introduction.texi               syntax-tables.texi~
introduction.texi~              text.texi
introduction.txt                text.texi~
...
---------- Buffer: *shell* ----------
@end group
@end smallexample
@end defun

@c @deffn Command process-send-region process-name start end
@deffn $B%3%^%s%I(B process-send-region process-name start end
@c This function sends the text in the region defined by @var{start} and
@c @var{end} as standard input to @var{process-name}, which is a process or
@c a process name.  (If it is @code{nil}, the current buffer's process is
@c used.)
$B$3$N4X?t$O!"(B@var{start}$B$H(B@var{end}$B$GDj5A$5$l$kNN0hFb$N%F%-%9%H$r(B
$BI8=`F~NO$H$7$F%W%m%;%9(B@var{process-name}$B$XAw$k!#(B
@var{process-name}$B$O%W%m%;%9$+%W%m%;%9L>$G$"$k$3$H!#(B
$B!J(B@code{nil}$B$G$"$k$H!"%+%l%s%H%P%C%U%!$N%W%m%;%9$r;H$&!#!K(B

@c An error is signaled unless both @var{start} and @var{end} are
@c integers or markers that indicate positions in the current buffer.  (It
@c is unimportant which number is larger.)
@var{start}$B$H(B@var{end}$B$N$I$A$i$+$,(B
$B%+%l%s%H%P%C%U%!Fb$N0LCV$rI=$9@0?t$G$b%^!<%+$G$b$J$$$H!"(B
$B%(%i!<$rDLCN$9$k!#(B
$B!J$I$A$i$,Bg$-$J?t$G$"$k$+$O=EMW$G$O$J$$!#!K(B
@end deffn

@defun process-send-eof &optional process-name
@c   This function makes @var{process-name} see an end-of-file in its
@c input.  The @sc{eof} comes after any text already sent to it.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process-name}$B$,F~NO$G(B
$B!V%U%!%$%k$N=*$j(B@sc{eof}$B!W$r8+$k$h$&$K$9$k!#(B
@sc{eof}$B$O$=$l$^$G$KAw$C$?%F%-%9%H$N$"$H$K$"$k!#(B

@c   If @var{process-name} is not supplied, or if it is @code{nil}, then
@c this function sends the @sc{eof} to the current buffer's process.  An
@c error is signaled if the current buffer has no process.
@var{process-name}$B$r;XDj$7$J$+$C$?$j(B@code{nil}$B$G$"$k$H!"(B
$B$3$N4X?t$O%+%l%s%H%P%C%U%!$N%W%m%;%9$K(B@sc{eof}$B$rAw$k!#(B
$B%+%l%s%H%P%C%U%!$K%W%m%;%9$,$J$$$H%(%i!<$rDLCN$9$k!#(B

@c   The function returns @var{process-name}.
$B4X?t$O(B@var{process-name}$B$rJV$9!#(B

@smallexample
@group
(process-send-eof "shell")
     @result{} "shell"
@end group
@end smallexample
@end defun

@node Signals to Processes
@c @section Sending Signals to Processes
@section $B%W%m%;%9$K%7%0%J%k$rAw$k(B
@c @cindex process signals
@c @cindex sending signals
@c @cindex signals
@cindex $B%W%m%;%9%7%0%J%k(B
@cindex $B%7%0%J%k$rAw$k(B
@cindex $B%7%0%J%k(B

@c   @dfn{Sending a signal} to a subprocess is a way of interrupting its
@c activities.  There are several different signals, each with its own
@c meaning.  The set of signals and their names is defined by the operating
@c system.  For example, the signal @code{SIGINT} means that the user has
@c typed @kbd{C-c}, or that some analogous thing has happened.
$B%5%V%W%m%;%9$K(B@dfn{$B%7%0%J%k$rAw$k(B}$B$3$H$O!"(B
$B%5%V%W%m%;%9$NF0:n$K3d$j9~$`0lJ}K!$G$9!#(B
$B$=$l$>$lFH<+$N0UL#$r;}$D0[$J$k%7%0%J%k$,$$$/$D$+$"$j$^$9!#(B
$B0lO"$N%7%0%J%k$H$=$l$i$NL>A0$O!"%*%Z%l!<%F%#%s%0%7%9%F%`$,Dj5A$7$^$9!#(B
$B$?$H$($P!"%7%0%J%k(B@code{SIGINT}$B$O!"%f!<%6!<$,(B@kbd{C-c}$B$rBG$C$?!"(B
$B$"$k$$$O!"$=$l$HF1MM$J$3$H$,5/$3$C$?$3$H$r0UL#$7$^$9!#(B

@c   Each signal has a standard effect on the subprocess.  Most signals
@c kill the subprocess, but some stop or resume execution instead.  Most
@c signals can optionally be handled by programs; if the program handles
@c the signal, then we can say nothing in general about its effects.
$B3F%7%0%J%k$K$O!"%5%V%W%m%;%9$KBP$9$kI8=`E*$J8z2L$,$"$j$^$9!#(B
$B$[$H$s$I$N%7%0%J%k$O%5%V%W%m%;%9$r%-%k$7$^$9$,!"(B
$B$=$N<B9T$r0l;~Dd;_$7$?$j:F3+$9$k$b$N$b$"$j$^$9!#(B
$B%W%m%0%i%`$,%7%0%J%k$r=hM}$7$F$$$k>l9g$K$O!"(B
$B%7%0%J%k$N8z2L$r0lHLE*$K=R$Y$k$3$H$O$G$-$^$;$s!#(B

@c   You can send signals explicitly by calling the functions in this
@c section.  Emacs also sends signals automatically at certain times:
@c killing a buffer sends a @code{SIGHUP} signal to all its associated
@c processes; killing Emacs sends a @code{SIGHUP} signal to all remaining
@c processes.  (@code{SIGHUP} is a signal that usually indicates that the
@c user hung up the phone.)
$BK\@a$N4X?t$r8F$S=P$7$F%7%0%J%k$rL@<(E*$KAw$k$3$H$,$G$-$^$9!#(B
$B$^$?!"(BEmacs$B$OFCDj$N>lLL$G<+F0E*$K%7%0%J%k$rAw$j$^$9!#(B
$B%P%C%U%!$r:o=|$9$k$H!"$=$N%P%C%U%!$KBP1~IU$1$i$l$F$$$k$9$Y$F$N(B
$B%W%m%;%9$K%7%0%J%k(B@code{SIGHUP}$B$rAw$j$^$9!#(B
Emacs$B$r=*N;$9$k$H$-$K$O!"F0:n$7$F$$$k$9$Y$F$N%5%V%W%m%;%9$K(B
$B%7%0%J%k(B@code{SIGHUP}$B$rAw$j$^$9!#(B
$B!J(B@code{SIGHUP}$B$O!"%f!<%6!<$,EEOC$r@Z$C$?$3$H$rIaDL$OI=$9%7%0%J%k!#!K(B

@c   Each of the signal-sending functions takes two optional arguments:
@c @var{process-name} and @var{current-group}.
$B%7%0%J%k$rAw$k3F4X?t$O!">JN,2DG=$J(B2$B$D$N0z?t!"(B
@var{process-name}$B$H(B@var{current-group}$B$r<u$1IU$1$^$9!#(B

@c   The argument @var{process-name} must be either a process, the name of
@c one, or @code{nil}.  If it is @code{nil}, the process defaults to the
@c process associated with the current buffer.  An error is signaled if
@c @var{process-name} does not identify a process.
$B0z?t(B@var{process-name}$B$O!"%W%m%;%9!"%W%m%;%9L>!"(B@code{nil}$B$N$$$:$l$+$G$9!#(B
$B$3$l$,(B@code{nil}$B$G$"$k$H!"%+%l%s%H%P%C%U%!$KBP1~IU$1$i$l$F$$$k%W%m%;%9$,(B
$B%G%U%)%k%H$K$J$j$^$9!#(B
@var{process-name}$B$,%W%m%;%9$r;XDj$7$J$$$H%(%i!<$rDLCN$7$^$9!#(B

@c   The argument @var{current-group} is a flag that makes a difference
@c when you are running a job-control shell as an Emacs subprocess.  If it
@c is non-@code{nil}, then the signal is sent to the current process-group
@c of the terminal that Emacs uses to communicate with the subprocess.  If
@c the process is a job-control shell, this means the shell's current
@c subjob.  If it is @code{nil}, the signal is sent to the process group of
@c the immediate subprocess of Emacs.  If the subprocess is a job-control
@c shell, this is the shell itself.
$B0z?t(B@var{current-group}$B$O!"(BEmacs$B$N%5%V%W%m%;%9$H$7$F(B
$B%8%g%V@)8f2DG=$J%7%'%k$r<B9T$7$F$$$k$H$-$K0c$$$,8=$l$k%U%i%0$G$9!#(B
$B$3$l$,(B@code{nil}$B0J30$G$"$k$H!"(B
Emacs$B$,%5%V%W%m%;%9$H$NDL?.$KMQ$$$F$$$kC<Kv$N8=:_$N%W%m%;%9%0%k!<%W$K(B
$B%7%0%J%k$rAw$j$^$9!#(B
$B%W%m%;%9$,%8%g%V@)8f2DG=$J%7%'%k$G$"$k$H!"(B
$B$3$l$O%7%'%k$N8=:_$N%5%V%8%g%V(B
@footnote{$B!ZLuCm![%7%'%k$N$b$H$GF0$$$F$$$k%W%m%;%972(B}
$B$G$"$k$3$H$r0UL#$7$^$9!#(B
@code{nil}$B$G$"$k$H!"(BEmacs$B$N%5%V%W%m%;%9$ND>@\$N%W%m%;%9%0%k!<%W$K(B
$B%7%0%J%k$rAw$j$^$9!#(B
$B%W%m%;%9$,%8%g%V@)8f2DG=$J%7%'%k$G$"$k$H!"$3$l$O%7%'%k$=$N$b$N$G$9!#(B

@c   The flag @var{current-group} has no effect when a pipe is used to
@c communicate with the subprocess, because the operating system does not
@c support the distinction in the case of pipes.  For the same reason,
@c job-control shells won't work when a pipe is used.  See
@c @code{process-connection-type} in @ref{Asynchronous Processes}.
$B%*%Z%l!<%F%#%s%0%7%9%F%`$O%Q%$%W$G$O%W%m%;%9%0%k!<%W$r07$o$J$$$?$a!"(B
$B%5%V%W%m%;%9$H$NDL?.$K%Q%$%W$rMQ$$$F$$$k>l9g$K$O!"(B
$B%U%i%0(B@var{current-group}$B$K$O8z2L$O$"$j$^$;$s!#(B
$BF1$8M}M3$G!"%Q%$%W$rMQ$$$F$$$k>l9g$K$O(B
$B%8%g%V@)8f2DG=$J%7%'%k!J$N%8%g%V@)8f5!G=!K$OF/$-$^$;$s!#(B
@ref{Asynchronous Processes}$B$N(B
@code{process-connection-type}$B$r;2>H$7$F$/$@$5$$!#(B

@defun interrupt-process &optional process-name current-group
@c This function interrupts the process @var{process-name} by sending the
@c signal @code{SIGINT}.  Outside of Emacs, typing the ``interrupt
@c character'' (normally @kbd{C-c} on some systems, and @code{DEL} on
@c others) sends this signal.  When the argument @var{current-group} is
@c non-@code{nil}, you can think of this function as ``typing @kbd{C-c}''
@c on the terminal by which Emacs talks to the subprocess.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process-name}$B$K(B
$B%7%0%J%k(B@code{SIGINT}$B$rAw$C$F3d$j9~$`!#(B
Emacs$B$N30B&$G$O!"!X3d$j9~$_J8;z!Y!JIaDL!"(B@kbd{C-c}$B$G$"$k%7%9%F%`$b$"$j!"(B
$B$=$NB>$N%7%9%F%`$G$O(B@code{DEL}$B!K$rBG$D$H$3$N%7%0%J%k$rAw$k!#(B
$B0z?t(B@var{current-group}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B$3$N4X?t$O!"(BEmacs$B$,%5%V%W%m%;%9$HDL?.$7$F$$$kC<Kv>e$G(B
$B!X(B@kbd{C-c}$B$rBG$D!Y$H9M$($k$3$H$,$G$-$k!#(B
@end defun

@defun kill-process &optional process-name current-group
@c This function kills the process @var{process-name} by sending the
@c signal @code{SIGKILL}.  This signal kills the subprocess immediately,
@c and cannot be handled by the subprocess.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process-name}$B$K(B
$B%7%0%J%k(B@code{SIGKILL}$B$rAw$C$F%-%k$9$k!#(B
$B$3$N%7%0%J%k$O%5%V%W%m%;%9$rB(:B$K%-%k$7!"(B
$B%5%V%W%m%;%9$O$3$l$r=hM}$G$-$J$$!#(B
@end defun

@defun quit-process &optional process-name current-group
@c This function sends the signal @code{SIGQUIT} to the process
@c @var{process-name}.  This signal is the one sent by the ``quit
@c character'' (usually @kbd{C-b} or @kbd{C-\}) when you are not inside
@c Emacs.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process-name}$B$K%7%0%J%k(B@code{SIGQUIT}$B$rAw$k!#(B
$B$3$N%7%0%J%k$O!"!XCfCGJ8;z!Y(B
$B!J(BEmacs$B$N30B&$G$OIaDL$O(B@kbd{C-b}$B$d(B@kbd{C-\}$B!K$,(B
$BAw$k%7%0%J%k$HF1$8$b$N$G$"$k!#(B
@end defun

@defun stop-process &optional process-name current-group
@c This function stops the process @var{process-name} by sending the
@c signal @code{SIGTSTP}.  Use @code{continue-process} to resume its
@c execution.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process-name}$B$K(B
$B%7%0%J%k(B@code{SIGTSTP}$B$rAw$C$F0l;~Dd;_$5$;$k!#(B
$B$=$N<B9T$r:F3+$5$;$k$K$O(B@code{continue-process}$B$r;H$&!#(B

@c Outside of Emacs, on systems with job control, the ``stop character''
@c (usually @kbd{C-z}) normally sends this signal.  When
@c @var{current-group} is non-@code{nil}, you can think of this function as
@c ``typing @kbd{C-z}'' on the terminal Emacs uses to communicate with the
@c subprocess.
Emacs$B$N30B&$G%8%g%V@)8f2DG=$J%7%9%F%`$G$O!"(B
$B!X0l;~Dd;_J8;z!Y!JIaDL$O(B@kbd{C-z}$B!K$,IaDL$O$3$N%7%0%J%k$rAw$k!#(B
@var{current-group}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B$3$N4X?t$O!"(BEmacs$B$,%5%V%W%m%;%9$HDL?.$7$F$$$kC<Kv>e$G(B
$B!X(B@kbd{C-z}$B$rBG$D!Y$H9M$($k$3$H$,$G$-$k!#(B
@end defun

@defun continue-process &optional process-name current-group
@c This function resumes execution of the process @var{process} by sending
@c it the signal @code{SIGCONT}.  This presumes that @var{process-name} was
@c stopped previously.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$K(B
$B%7%0%J%k(B@code{SIGTCONT}$B$rAw$C$F<B9T$r:F3+$5$;$k!#(B
$B0JA0$K0l;~Dd;_$5$;$i$l$?(B@var{process}$B$r:F3+$9$k!#(B
@end defun

@c Emacs 19 feature
@defun signal-process pid signal
@c This function sends a signal to process @var{pid}, which need not be
@c a child of Emacs.  The argument @var{signal} specifies which signal
@c to send; it should be an integer.
$B$3$N4X?t$O!"I,$:$7$b(BEmacs$B$N;R%W%m%;%9$G$O$J$$(B
$B%W%m%;%9(B@var{pid}$B$K%7%0%J%k$rAw$k!#(B
$B0z?t(B@var{signal}$B$O!"Aw$k$Y$-%7%0%J%k$r@0?t$G;XDj$9$k!#(B
@end defun

@node Output from Processes
@c @section Receiving Output from Processes
@section $B%W%m%;%9$+$i$N=PNO$r<u$1<h$k(B
@c @cindex process output
@c @cindex output from processes
@cindex $B%W%m%;%9$N=PNO(B
@cindex $B=PNO!"%W%m%;%9(B

@c   There are two ways to receive the output that a subprocess writes to
@c its standard output stream.  The output can be inserted in a buffer,
@c which is called the associated buffer of the process, or a function
@c called the @dfn{filter function} can be called to act on the output.  If
@c the process has no buffer and no filter function, its output is
@c discarded.
$B%5%V%W%m%;%9$,I8=`=PNO$K=q$/=PNO$r<u$1<h$kJ}K!$O(B2$B$D$"$j$^$9!#(B
$B%W%m%;%9$KBP1~IU$1$i$l$?%P%C%U%!$K=PNO$rA^F~$9$k$+!"(B
$B$"$k$$$O!"(B@dfn{$B%U%#%k%?4X?t(B}$B!J(Bfilter function$B!K$H8F$P$l$k4X?t$r(B
$B=PNO$KBP$7$F:nMQ$5$;$^$9!#(B
$B%W%m%;%9$K%P%C%U%!$b%U%#%k%?4X?t$b$J$1$l$P!"$=$N=PNO$OGK4~$7$^$9!#(B

@c   Output from a subprocess can arrive only while Emacs is waiting: when
@c reading terminal input, in @code{sit-for} and @code{sleep-for}
@c (@pxref{Waiting}), and in @code{accept-process-output} (@pxref{Accepting
@c Output}).  This minimizes the problem of timing errors that usually
@c plague parallel programming.  For example, you can safely create a
@c process and only then specify its buffer or filter function; no output
@c can arrive before you finish, if the code in between does not call any
@c primitive that waits.
$B%5%V%W%m%;%9$+$i$N=PNO$O!"(BEmacs$B$,BT$C$F$$$k!"$D$^$j!"(B
$BC<KvF~NO$rFI$s$G$$$k$H$-!"(B
@code{sit-for}$B$d(B@code{sleep-for}$B$r<B9TCf$N$H$-!J(B@pxref{Waiting}$B!K!"(B
@code{accept-process-output}$B!J(B@pxref{Accepting Output}$B!K$r<B9TCf$N$H$-$K(B
$B$@$1E~Ce$7$^$9!#(B
$B$3$l$K$h$j!"JB9T%W%m%0%i%`$rIaDL$OG:$^$9$h$&$J(B
$B%?%$%_%s%0%(%i!<$NLdBj$r:G>.$KM^$($^$9!#(B
$B$?$H$($P!"0BA4$K%W%m%;%9$r:n@.$7$F$+$i!"(B
$B%P%C%U%!$+%U%#%k%?4X?t$r;XDj$G$-$^$9!#(B
$B$3$N=hM}$NESCf$GBT$D$h$&$J4pK\4X?t$r8F$S=P$5$J$1$l$P!"(B
$B=PNO$OE~Ce$7$^$;$s!#(B

@c   Subprocess output is normally decoded using a coding system before the
@c buffer or filter function receives it, much like text read from a file.
@c You can use @code{set-process-coding-system} to specify which coding
@c system to use (@pxref{Process Information}).  Otherwise, the coding
@c system comes from @code{coding-system-for-read}, if that is
@c non-@code{nil}; or else from the defaulting mechanism (@pxref{Default
@c Coding Systems}).
$B%U%!%$%k$+$iFI$`%F%-%9%H$HF1MM$K!"(B
$B%5%V%W%m%;%9$N=PNO$O!"%P%C%U%!$d%U%#%k%?4X?t$,<u$1<h$k$^$($K(B
$B%3!<%G%#%s%0%7%9%F%`$rMQ$$$FIaDL$OI|9f2=$7$^$9!#(B
@code{set-process-coding-system}$B$G(B
$B;HMQ$9$k%3!<%G%#%s%0%7%9%F%`$r;XDj$G$-$^$9(B
$B!J(B@pxref{Process Information}$B!K!#(B
$B$5$b$J$1$l$P!"(B@code{coding-system-for-read}$B$,(B
@code{nil}$B0J30$G$"$l$P$3$l$r;H$$$^$9!#(B
$B$=$l0J30$G$O%G%U%)%k%H$N5!9=$G7h$^$k$b$N$r;H$$$^$9(B
$B!J(B@pxref{Default Coding Systems}$B!K!#(B

@c   @strong{Warning:} Coding systems such as @code{undecided} which
@c determine the coding system from the data do not work entirely reliably
@c with asynchronous subprocess output.  This is because Emacs has to
@c process asynchronous subprocess output in batches, as it arrives.  Emacs
@c must try to detect the proper coding system from one batch at a time,
@c and this does not always work.  Therefore, if at all possible, use a
@c coding system which determines both the character code conversion and
@c the end of line conversion---that is, one like @code{latin-1-unix},
@c rather than @code{undecided} or @code{latin-1}.
@strong{$B7Y9p!'(B}@code{ }
$B%G!<%?$+$i%3!<%G%#%s%0%7%9%F%`$r7hDj$9$k(B@code{undecided}$B$N$h$&$J(B
$B%3!<%G%#%s%0%7%9%F%`$O!"HsF14|%5%V%W%m%;%9$N=PNO$KBP$7$F$O(B
$B40A4$K?.Mj@-$N$"$kF0:n$O$G$-$J$$!#(B
$B$3$l$O!"(BEmacs$B$,HsF14|%5%V%W%m%;%9$N=PNO$,(B
$BE~Ce$9$k$?$S$K0l2t$G=hM}$9$k$+$i$G$"$k!#(B
Emacs$B$O(B1$B$D$N2t$+$i@5$7$$JQ49$r8!=P$7$h$&$H;n$_$k$,!"(B
$B$3$l$,$D$M$KF0:n$9$k$H$O8B$i$J$$!#(B
$B$7$?$,$C$F!"2DG=$J8B$j(B
$BJ8;z%3!<%IJQ49$H9TKvJQ49$NN>J}$r;XDj$7$?%3!<%G%#%s%0%7%9%F%`$r;H$&!#(B
$B$D$^$j!"(B@code{undecided}$B$d(B@code{latin-1}$B$J$I$G$O$J$/!"(B
@code{latin-1-unix}$B$N$h$&$J$b$N$r;H$&!#(B

@menu
* Process Buffers::       If no filter, output is put in a buffer.
* Filter Functions::      Filter functions accept output from the process.
* Accepting Output::      Explicitly permitting subprocess output.
                            Waiting for subprocess output.
@end menu

@node Process Buffers
@c @subsection Process Buffers
@subsection $B%W%m%;%9%P%C%U%!(B

@c   A process can (and usually does) have an @dfn{associated buffer},
@c which is an ordinary Emacs buffer that is used for two purposes: storing
@c the output from the process, and deciding when to kill the process.  You
@c can also use the buffer to identify a process to operate on, since in
@c normal practice only one process is associated with any given buffer.
@c Many applications of processes also use the buffer for editing input to
@c be sent to the process, but this is not built into Emacs Lisp.
$B%W%m%;%9$K$O(B@dfn{$BBP1~IU$1$i$l$?%P%C%U%!(B}$B$,!JIaDL$O!K$"$j$^$9!#(B
$B$=$N%P%C%U%!$O(BEmacs$B$NIaDL$N%P%C%U%!$G$"$j!"(B2$B$D$NL\E*$K;H$o$l$^$9!#(B
$B%W%m%;%9$+$i$N=PNO$rJ]B8$9$k$3$H$H!"(B
$B%W%m%;%9$,%-%k$5$l$?$3$H$rH=Dj$9$k$?$a$G$9!#(B
$B%P%C%U%!$rMQ$$$F$=$l$rA`:n$7$F$$$k%W%m%;%9$r<1JL$9$k$3$H$b$G$-$^$9!#(B
$BIaDL$O(B1$B$D$N%P%C%U%!$K(B1$B$D$N%W%m%;%9$rBP1~IU$1$k$+$i$G$9!#(B
$B%W%m%;%9$NB?$/$N1~MQ$G$O!"%W%m%;%9$XAw$kF~NO$rJT=8$9$k$?$a$K(B
$B%P%C%U%!$r;H$$$^$9$,!"$3$l$O(BEmacs Lisp$B$KAH$_9~$^$l$?$3$H$G$O$"$j$^$;$s!#(B

@c   Unless the process has a filter function (@pxref{Filter Functions}),
@c its output is inserted in the associated buffer.  The position to insert
@c the output is determined by the @code{process-mark}, which is then
@c updated to point to the end of the text just inserted.  Usually, but not
@c always, the @code{process-mark} is at the end of the buffer.
$B%W%m%;%9$K%U%#%k%?4X?t!J(B@pxref{Filter Functions}$B!K$,$J$1$l$P!"(B
$B$=$N=PNO$OBP1~IU$1$i$l$?%P%C%U%!$KA^F~$5$l$^$9!#(B
$B=PNO$NA^F~0LCV$O(B@code{process-mark}$B$G7hDj$5$l!"(B
@code{process-mark}$B$OA^F~$7$?$P$+$j$N%F%-%9%H$NKvHx$r(B
$B;X$9$h$&$K99?7$5$l$^$9!#(B
@code{process-mark}$B$OIaDL$O%P%C%U%!$NKvHx$K$"$j$^$9$,!"(B
$B$D$M$K$=$&$G$"$k$H$O8B$j$^$;$s!#(B

@defun process-buffer process
@c This function returns the associated buffer of the process
@c @var{process}.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$KBP1~IU$1$i$l$F$$$k%P%C%U%!$rJV$9!#(B

@smallexample
@group
(process-buffer (get-process "shell"))
     @result{} #<buffer *shell*>
@end group
@end smallexample
@end defun

@defun process-mark process
@c This function returns the process marker for @var{process}, which is the
@c marker that says where to insert output from the process.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$+$i$N=PNO$rA^F~$9$k2U=j$r;XDj$9$k(B
@var{process}$B$N%W%m%;%9%^!<%+$rJV$9!#(B

@c If @var{process} does not have a buffer, @code{process-mark} returns a
@c marker that points nowhere.
@var{process}$B$K%P%C%U%!$,$J$1$l$P!"(B
@code{process-mark}$B$O$I$3$b;X$7$F$$$J$$%^!<%+$G$"$k!#(B

@c Insertion of process output in a buffer uses this marker to decide where
@c to insert, and updates it to point after the inserted text.  That is why
@c successive batches of output are inserted consecutively.
$B%P%C%U%!$K%W%m%;%9=PNO$rA^F~$9$k:]$K$O!"(B
$BA^F~2U=j$r7hDj$9$k$?$a$K$3$N%^!<%+$r;HMQ$7!"(B
$BA^F~$7$?%F%-%9%H$NKvHx$r;X$9$h$&$K$3$N%^!<%+$r99?7$9$k!#(B
$B$3$l$K$h$j!"=PNO$NO"B3$7$?2t$r=g$KA^F~$G$-$k$N$G$"$k!#(B

@c Filter functions normally should use this marker in the same fashion
@c as is done by direct insertion of output in the buffer.  A good
@c example of a filter function that uses @code{process-mark} is found at
@c the end of the following section.
$B%P%C%U%!$K=PNO$rD>@\A^F~$9$k>l9g$HF1MM$K!"(B
$B%U%#%k%?4X?t$O$3$N%^!<%+$r07$&$Y$-$G$"$k!#(B
@code{process-mark}$B$rMQ$$$?%U%#%k%?4X?t$N9%Nc$O!"0J2<$N@a$K$"$k!#(B

@c When the user is expected to enter input in the process buffer for
@c transmission to the process, the process marker separates the new input
@c from previous output.
$B%W%m%;%9$XAw$k$?$a$K%f!<%6!<$,%W%m%;%9%P%C%U%!$K(B
$BF~NO$9$k$3$H$,M=A[$5$l$k$H$-$O!"(B
$B%W%m%;%9%^!<%+$O?7$?$JF~NO$H$=$l0JA0$N=PNO$r6h@Z$k!#(B
@end defun

@defun set-process-buffer process buffer
@c This function sets the buffer associated with @var{process} to
@c @var{buffer}.  If @var{buffer} is @code{nil}, the process becomes
@c associated with no buffer.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$K%P%C%U%!(B@var{buffer}$B$rBP1~IU$1$k!#(B
@var{buffer}$B$,(B@code{nil}$B$G$"$k$H!"(B
$B%W%m%;%9$KBP1~IU$1$i$l$?%P%C%U%!$O$J$$!#(B
@end defun

@defun get-buffer-process buffer-or-name
@c This function returns the process associated with @var{buffer-or-name}.
@c If there are several processes associated with it, then one is chosen.
@c (Currently, the one chosen is the one most recently created.)  It is
@c usually a bad idea to have more than one process associated with the
@c same buffer.
$B$3$N4X?t$O(B@var{buffer-or-name}$B$KBP1~IU$1$i$l$?%W%m%;%9$rJV$9!#(B
$B%P%C%U%!$KJ#?t$N%W%m%;%9$,BP1~IU$1$i$l$F$$$k>l9g$K$O!"(B
$B$=$l$i$N(B1$B$D$rA*$V!#(B
$B!J8=>u$G$O!"$b$C$H$b:G6a$K:n$i$l$?%W%m%;%9$rA*$V!#!K(B
$BF1$8%P%C%U%!$KJ#?t$N%W%m%;%9$rBP1~IU$1$k$3$H$O0lHL$K$O$h$/$J$$!#(B

@smallexample
@group
(get-buffer-process "*shell*")
     @result{} #<process shell>
@end group
@end smallexample

@c Killing the process's buffer deletes the process, which kills the
@c subprocess with a @code{SIGHUP} signal (@pxref{Signals to Processes}).
$B%W%m%;%9$N%P%C%U%!$r:o=|$9$k$H!"(B
$B%5%V%W%m%;%9$K%7%0%J%k(B@code{SIGHUP}$B$rAw$C$F%W%m%;%9$r:o=|$9$k(B
$B!J(B@pxref{Signals to Processes}$B!K!#(B
@end defun

@node Filter Functions
@c @subsection Process Filter Functions
@subsection $B%W%m%;%9%U%#%k%?4X?t(B
@c @cindex filter function
@c @cindex process filter
@cindex $B%U%#%k%?4X?t(B
@cindex $B%W%m%;%9%U%#%k%?(B

@c   A process @dfn{filter function} is a function that receives the
@c standard output from the associated process.  If a process has a filter,
@c then @emph{all} output from that process is passed to the filter.  The
@c process buffer is used directly for output from the process only when
@c there is no filter.
$B%W%m%;%9$N(B@dfn{$B%U%#%k%?4X?t(B}$B!J(Bfilter function$B!K$O!"(B
$BBP1~IU$1$i$l$?%W%m%;%9$+$i$NI8=`=PNO$r<u$1<h$k4X?t$G$9!#(B
$B%W%m%;%9$K%U%#%k%?$,$"$k$H!"$=$N%W%m%;%9$+$i$N(B@emph{$B$9$Y$F(B}$B$N=PNO$O(B
$B%U%#%k%?$KEO$5$l$^$9!#(B
$B%W%m%;%9$K%U%#%k%?$,$J$$>l9g$K8B$C$F!"(B
$B%W%m%;%9$+$i$N=PNO8~$1$K%W%m%;%9%P%C%U%!$rD>@\;H$$$^$9!#(B

@c   The filter function can only be called when Emacs is waiting for
@c something, because process output arrives only at such times.  Emacs
@c waits when reading terminal input, in @code{sit-for} and
@c @code{sleep-for} (@pxref{Waiting}), and in @code{accept-process-output}
@c (@pxref{Accepting Output}).
$B%U%#%k%?4X?t$O!"(BEmacs$B$,$J$K$+$rBT$C$F$$$k$H$-$K$N$_8F$P$l$^$9!#(B
$B$=$N$h$&$J4|4V$K$N$_%W%m%;%9$N=PNO$,E~Ce$9$k$+$i$G$9!#(B
Emacs$B$,BT$D$N$O!"C<KvF~NO$rFI$s$G$$$k$H$-!"(B
@code{sit-for}$B$d(B@code{sleep-for}$B$r<B9TCf$N$H$-!J(B@pxref{Waiting}$B!K!"(B
@code{accept-process-output}$B!J(B@pxref{Accepting Output}$B!K$r<B9TCf$N$H$-$G$9!#(B

@c   A filter function must accept two arguments: the associated process
@c and a string, which is output just received from it.  The function is
@c then free to do whatever it chooses with the output.
$B%U%#%k%?4X?t$O(B2$B$D$N0z?t!"(B
$BBP1~IU$1$i$l$?%W%m%;%9$H$=$N%W%m%;%9$+$i<u$1<h$C$?$P$+$j$N=PNO$G$"$kJ8;zNs$r(B
$B<u$1<h$j$^$9!#(B
$B4X?t$O=PNO$KBP$7$F$J$K$r9T$C$F$b$+$^$$$^$;$s!#(B

@c   Quitting is normally inhibited within a filter function---otherwise,
@c the effect of typing @kbd{C-g} at command level or to quit a user
@c command would be unpredictable.  If you want to permit quitting inside a
@c filter function, bind @code{inhibit-quit} to @code{nil}.
@c @xref{Quitting}.
$B%U%#%k%?4X?t$NFbB&$G$OCfCG$OIaDL$O6X;_$5$l$F$$$^$9!#(B
$B$5$b$J$$$H!"%3%^%s%I%l%Y%k$GBG$C$?(B@kbd{C-g}$B$N8z2L$d!"(B
$B%f!<%6!<%3%^%s%I$rCfCG$9$k$?$a$KBG$C$?(B@kbd{C-g}$B$N8z2L$OM=B,$G$-$^$;$s!#(B
$B%U%#%k%?4X?t$NFbB&$GCfCG$r9T$$$?$$>l9g$K$O!"(B
@code{inhibit-quit}$B$K(B@code{nil}$B$rB+G{$7$^$9!#(B
@xref{Quitting}$B!#(B

@c   If an error happens during execution of a filter function, it is
@c caught automatically, so that it doesn't stop the execution of whatever
@c program was running when the filter function was started.  However, if
@c @code{debug-on-error} is non-@code{nil}, the error-catching is turned
@c off.  This makes it possible to use the Lisp debugger to debug the
@c filter function.  @xref{Debugger}.
$B%U%#%k%?4X?t$N<B9TCf$K%(%i!<$,H/@8$9$k$H$=$N%(%i!<$O<+F0E*$KJaB*$5$l!"(B
$B%U%#%k%?4X?t$r;OF0$7$?$H$-$KF0$$$F$$$?(B
$B%W%m%0%i%`$N<B9T$rDd;_$7$J$$$h$&$K$7$^$9!#(B
$B$7$+$7!"(B@code{debug-on-error}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B%(%i!<$rJaB*$7$^$;$s!#(B
$B$3$l$K$h$j!"(BLisp$B%G%P%C%,$G%U%#%k%?4X?t$r%G%P%C%0$G$-$^$9!#(B
@xref{Debugger}$B!#(B

@c   Many filter functions sometimes or always insert the text in the
@c process's buffer, mimicking the actions of Emacs when there is no
@c filter.  Such filter functions need to use @code{set-buffer} in order to
@c be sure to insert in that buffer.  To avoid setting the current buffer
@c semipermanently, these filter functions must save and restore the
@c current buffer.  They should also update the process marker, and in some
@c cases update the value of point.  Here is how to do these things:
$BB?$/$N%U%#%k%?4X?t$O!"$H$-$I$-$"$k$$$O$D$M$K!"(B
$B%W%m%;%9$N%P%C%U%!$K%F%-%9%H$rA^F~$7$^$9!#(B
$B$3$l$O%U%#%k%?4X?t$,$J$$$H$-$N(BEmacs$B$NF0:n$rLOJo$9$k$b$N$G$9!#(B
$B$=$N$h$&$J%U%#%k%?4X?t$G$O!"BP>]$N%P%C%U%!$KA^F~$9$k$?$a$K(B
@code{set-buffer}$B$r;H$&I,MW$,$"$j$^$9!#(B
$B%+%l%s%H%P%C%U%!$r$J$+$P915WE*$K@Z$jBX$($J$$$h$&$K!"(B
$B$3$l$i$N%U%#%k%?4X?t$O%+%l%s%H%P%C%U%!$r5-O?!?I|85$9$kI,MW$,$"$j$^$9!#(B
$B%W%m%;%9%^!<%+$r99?7$7!"I,MW$K1~$8$F%]%$%s%H$NCM$b99?7$7$^$9!#(B
$B$3$l$i$O$D$.$N$h$&$K9T$$$^$9!#(B

@smallexample
@group
(defun ordinary-insertion-filter (proc string)
  (with-current-buffer (process-buffer proc)
    (let ((moving (= (point) (process-mark proc))))
@end group
@group
      (save-excursion
@c         ;; @r{Insert the text, advancing the process marker.}
        ;; @r{$B%F%-%9%H$rA^F~$7!"%W%m%;%9%^!<%+$r?J$a$k(B}
        (goto-char (process-mark proc))
        (insert string)
        (set-marker (process-mark proc) (point)))
      (if moving (goto-char (process-mark proc))))))
@end group
@end smallexample

@noindent
@c The reason to use @code{with-current-buffer}, rather than using
@c @code{save-excursion} to save and restore the current buffer, is so as
@c to preserve the change in point made by the second call to
@c @code{goto-char}.
$B%+%l%s%H%P%C%U%!$r5-O?!?I|85$9$k$?$a$K(B@code{save-excursion}$B$G$O$J$/(B
@code{with-current-buffer}$B$r;H$&$N$O!"(B
2$BHVL\$N(B@code{goto-char}$B$N8F$S=P$7$G9T$&%]%$%s%H$N0\F08z2L$r(B
$BM-8z$K$9$k$?$a$G$9!#(B

@c   To make the filter force the process buffer to be visible whenever new
@c text arrives, insert the following line just before the
@c @code{with-current-buffer} construct:
$B?7$?$K%F%-%9%H$,E~Ce$9$k$?$S$K%W%m%;%9%P%C%U%!$,8+$($k$h$&$K(B
$B%U%#%k%?4X?t$G6/@)$9$k$K$O!"(B
$B$D$.$N$h$&$J9T$r(B@code{with-current-buffer}$B$ND>A0$KF~$l$^$9!#(B

@smallexample
(display-buffer (process-buffer proc))
@end smallexample

@c   To force point to the end of the new output, no matter where it was
@c previously, eliminate the variable @code{moving} and call
@c @code{goto-char} unconditionally.
$B%]%$%s%H0LCV$K4X$o$i$:$K?7$?$J=PNO$NKvHx$K%]%$%s%H$r0\F0$9$k$K$O!"(B
$BJQ?t(B@code{moving}$B$r:o=|$7$F!"(B
$BL5>r7o$K(B@code{goto-char}$B$r8F$S=P$7$^$9!#(B

@c   In earlier Emacs versions, every filter function that did regular
@c expression searching or matching had to explicitly save and restore the
@c match data.  Now Emacs does this automatically for filter functions;
@c they never need to do it explicitly.  @xref{Match Data}.
Emacs$B$N=i4|$NHG$G$O!"@55,I=8=$rC5:w$7$?$j0lCW=hM}$9$k%U%#%k%?4X?t$G$O!"(B
$B%^%C%A%G!<%?$rL@<(E*$KJ]B8!?I|85$9$kI,MW$,$"$j$^$7$?!#(B
$B:#$N(BEmacs$B$O!"%U%#%k%?4X?t$KBP$7$F$O$3$l$r<+F0E*$K9T$$$^$9$+$i!"(B
$B%U%#%k%?4X?t$GL@<(E*$K9T$&I,MW$O$"$j$^$;$s!#(B
@xref{Match Data}$B!#(B

@c   A filter function that writes the output into the buffer of the
@c process should check whether the buffer is still alive.  If it tries to
@c insert into a dead buffer, it will get an error.  The expression
@c @code{(buffer-name (process-buffer @var{process}))} returns @code{nil}
@c if the buffer is dead.
$B%W%m%;%9$N%P%C%U%!$K=PNO$r=q$-9~$`%U%#%k%?4X?t$O!"(B
$B$=$N%P%C%U%!$,M-8z$G$"$k$+$I$&$+$r8!::$9$k$Y$-$G$9!#(B
$BL58z$J%P%C%U%!$KA^F~$7$h$&$H$9$k$H%(%i!<$K$J$j$^$9!#(B
$B%P%C%U%!$,L58z$G$"$l$P!"(B
$B<0(B@code{(buffer-name (process-buffer @var{process}))}
$B$r<B9T$9$k$H(B@code{nil}$B$rJV$7$^$9!#(B

@c   The output to the function may come in chunks of any size.  A program
@c that produces the same output twice in a row may send it as one batch of
@c 200 characters one time, and five batches of 40 characters the next.  If
@c the filter looks for certain text strings in the subprocess output, make
@c sure to handle the case where one of these strings is split across two
@c or more batches of output.
$B4X?t$KEO$5$l$k=PNO$OG$0U$N%5%$%:$N2t$G$-$^$9!#(B
$BF1$8=PNO$r(B2$B2s@8@.$9$k%W%m%0%i%`$O!"(B
$B$"$k$H$-$K$O0lEY$K(B200$BJ8;z$N2t$r(B1$B$DAw$k>l9g$b$"$l$P!"(B
40$BJ8;z$N2t$r(B5$B$DAw$k>l9g$b$"$j$^$9!#(B
$B%5%V%W%m%;%9$N=PNO$+$iFCDj$N%F%-%9%HJ8;zNs$rC5$9%U%#%k%?$G$O!"(B
$B$=$N$h$&$JJ8;zNs$,(B2$B$D$+$=$l0J>e$N=PNO$N2t$KJ,3d$5$l$k>l9g$b(B
$B07$($k$h$&$K$7$^$9!#(B

@defun set-process-filter process filter
@c This function gives @var{process} the filter function @var{filter}.  If
@c @var{filter} is @code{nil}, it gives the process no filter.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$K%U%#%k%?4X?t(B@var{filter}$B$r;XDj$9$k!#(B
@var{filter}$B$,(B@code{nil}$B$G$"$k$H!"%W%m%;%9$K%U%#%k%?$O$J$$!#(B
@end defun

@defun process-filter process
@c This function returns the filter function of @var{process}, or @code{nil}
@c if it has none.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$N%U%#%k%?4X?t$rJV$9!#(B
$B$"$k$$$O!"%U%#%k%?4X?t$,$J$1$l$P(B@code{nil}$B$rJV$9!#(B
@end defun

@c   Here is an example of use of a filter function:
$B%U%#%k%?4X?t$N;HMQNc$r$D$.$K<($7$^$9!#(B

@smallexample
@group
(defun keep-output (process output)
   (setq kept (cons output kept)))
     @result{} keep-output
@end group
@group
(setq kept nil)
     @result{} nil
@end group
@group
(set-process-filter (get-process "shell") 'keep-output)
     @result{} keep-output
@end group
@group
(process-send-string "shell" "ls ~/other\n")
     @result{} nil
kept
     @result{} ("lewis@@slug[8] % "
@end group
@group
"FINAL-W87-SHORT.MSS    backup.otl              kolstad.mss~
address.txt             backup.psf              kolstad.psf
backup.bib~             david.mss               resume-Dec-86.mss~
backup.err              david.psf               resume-Dec.psf
backup.mss              dland                   syllabus.mss
"
"#backups.mss#          backup.mss~             kolstad.mss
")
@end group
@end smallexample

@ignore   @c The code in this example doesn't show the right way to do things.
Here is another, more realistic example, which demonstrates how to use
the process mark to do insertion in the same fashion as is done when
there is no filter function:

@smallexample
@group
;; @r{Insert input in the buffer specified by @code{my-shell-buffer}}
;;   @r{and make sure that buffer is shown in some window.}
(defun my-process-filter (proc str)
  (let ((cur (selected-window))
        (pop-up-windows t))
    (pop-to-buffer my-shell-buffer)
@end group
@group
    (goto-char (point-max))
    (insert str)
    (set-marker (process-mark proc) (point-max))
    (select-window cur)))
@end group
@end smallexample
@end ignore

@node Accepting Output
@c @subsection Accepting Output from Processes
@subsection $B%W%m%;%9$+$i$N=PNO$r<u$1<h$k(B

@c   Output from asynchronous subprocesses normally arrives only while
@c Emacs is waiting for some sort of external event, such as elapsed time
@c or terminal input.  Occasionally it is useful in a Lisp program to
@c explicitly permit output to arrive at a specific point, or even to wait
@c until output arrives from a process.
$BHsF14|%5%V%W%m%;%9$+$i$N=PNO$O!"(B
Emacs$B$,;~4VBT$A$dC<KvF~NO$J$I$N(B
$B$J$s$i$+$N30It;v>]$rBT$C$F$$$k$H$-$K$N$_E~Ce$7$^$9!#(B
Lisp$B%W%m%0%i%`$+$iFCDj$N>lLL$G=PNO$NE~Ce$rL@<(E*$K5v$7$?$j!"(B
$B%W%m%;%9$N=PNO$,E~Ce$9$k$N$rBT$D$3$H$,$G$-$k$HM-MQ$J$3$H$,$"$j$^$9!#(B

@defun accept-process-output &optional process seconds millisec
@c This function allows Emacs to read pending output from processes.  The
@c output is inserted in the associated buffers or given to their filter
@c functions.  If @var{process} is non-@code{nil} then this function does
@c not return until some output has been received from @var{process}.
$B$3$N4X?t$O!"(BEmacs$B$K%W%m%;%9$+$i$NL$=hM}$N=PNO$rFI$_<h$k$3$H$r5v$9!#(B
$B$=$N=PNO$O!"BP1~IU$1$i$l$?%P%C%U%!$KA^F~$5$l$k$+!"(B
$B%U%#%k%?4X?t$KM?$($i$l$k!#(B
@var{process}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B$3$N4X?t$O!"(B@var{process}$B$+$i$J$s$i$+$N=PNO$rF@$k$^$GLa$i$J$$!#(B

@c @c Emacs 19 feature
@c The arguments @var{seconds} and @var{millisec} let you specify timeout
@c periods.  The former specifies a period measured in seconds and the
@c latter specifies one measured in milliseconds.  The two time periods
@c thus specified are added together, and @code{accept-process-output}
@c returns after that much time whether or not there has been any
@c subprocess output.
$B0z?t(B@var{seconds}$B$H(B@var{millisec}$B$O!";~4V@Z$l$r;XDj$9$k!#(B
$BA0<T$OICC10L$N;~4V!"8e<T$O%_%jICC10L$N;~4V$r;XDj$9$k!#(B
$B;XDj$5$l$?(B2$B$D$N;~4V$O9g7W$5$l!"(B
$BG$0U$N%5%V%W%m%;%9$N=PNO$r<u$1<h$C$?$I$&$+$K4X$o$i$:!"(B
$B$=$N;~4V$@$17P2a$9$k$H(B@code{accept-process-output}$B$OLa$C$F$/$k!#(B

@c The argument @var{seconds} need not be an integer.  If it is a floating
@c point number, this function waits for a fractional number of seconds.
@c Some systems support only a whole number of seconds; on these systems,
@c @var{seconds} is rounded down.
$B0z?t(B@var{seconds}$B$O@0?t$G$"$kI,MW$O$J$$!#(B
$BIbF0>.?tE@?t$G$"$k$H!"$3$N4X?t$OICL$K~$N;~4V$bBT$D!#(B
$BICL$K~$r07$($J$$%7%9%F%`$b$"$k!#(B
$B$=$N$h$&$J%7%9%F%`$G$O!"(B@var{seconds}$B$r@Z$j2<$2$k!#(B

@c Not all operating systems support waiting periods other than multiples
@c of a second; on those that do not, you get an error if you specify
@c nonzero @var{millisec}.
$B$9$Y$F$N%*%Z%l!<%F%#%s%0%7%9%F%`$GICL$K~$r07$($k$o$1$G$O$J$$!#(B
$B07$($J$$%7%9%F%`$G(B@var{millisec}$B$K%<%m0J30$r;XDj$9$k$H(B
$B%(%i!<$K$J$k!#(B

@c The function @code{accept-process-output} returns non-@code{nil} if it
@c did get some output, or @code{nil} if the timeout expired before output
@c arrived.
$B4X?t(B@code{accept-process-output}$B$O!"(B
$B=PNO$rF@$k$H(B@code{nil}$B0J30$rJV$9!#(B
$B$"$k$$$O!"=PNO$,E~Ce$9$k$^$($K;~4V@Z$l$9$k$H(B@code{nil}$B$rJV$9!#(B
@end defun

@node Sentinels
@c @section Sentinels: Detecting Process Status Changes
@section $BHVJ<!'%W%m%;%9$N>uBVJQ2=$N8!=P(B
@c @cindex process sentinel
@c @cindex sentinel
@cindex $B%W%m%;%9$NHVJ<(B
@cindex $BHVJ<(B

@c   A @dfn{process sentinel} is a function that is called whenever the
@c associated process changes status for any reason, including signals
@c (whether sent by Emacs or caused by the process's own actions) that
@c terminate, stop, or continue the process.  The process sentinel is also
@c called if the process exits.  The sentinel receives two arguments: the
@c process for which the event occurred, and a string describing the type
@c of event.
@dfn{$B%W%m%;%9$NHVJ<(B}$B!J(Bprocess sentinel$B!K$O!"(B
$B%W%m%;%9$r=*N;!?0l;~Dd;_!?7QB3$5$;$k(B
$B!J(BEmacs$B$,Aw$C$?$+%W%m%;%9<+?H$NF0:n$K$h$C$F@85/$7$?!K%7%0%J%k$r4^$a$F(B
$BBP1~IU$1$i$l$?%W%m%;%9$N>uBV$,G$0U$NM}M3$GJQ2=$7$?$H$-$K(B
$B8F$S=P$5$l$k4X?t$G$9!#(B
$B%W%m%;%9$NHVJ<$O!"%W%m%;%9$,=*N;$7$F$b8F$S=P$5$l$^$9!#(B
$BHVJ<$O(B2$B$D$N0z?t!";v>]$,H/@8$7$?%W%m%;%9$H(B
$B;v>]$N<oN`$r5-=R$9$kJ8;zNs$r<u$1<h$j$^$9!#(B

@c   The string describing the event looks like one of the following:
$B;v>]$r5-=R$9$kJ8;zNs$O$D$.$N$H$*$j$G$9!#(B

@itemize @bullet
@item 
@code{"finished\n"}.

@item
@code{"exited abnormally with code @var{exitcode}\n"}.

@item
@code{"@var{name-of-signal}\n"}.

@item
@code{"@var{name-of-signal} (core dumped)\n"}.
@end itemize

@c   A sentinel runs only while Emacs is waiting (e.g., for terminal input,
@c or for time to elapse, or for process output).  This avoids the timing
@c errors that could result from running them at random places in the
@c middle of other Lisp programs.  A program can wait, so that sentinels
@c will run, by calling @code{sit-for} or @code{sleep-for}
@c (@pxref{Waiting}), or @code{accept-process-output} (@pxref{Accepting
@c Output}).  Emacs also allows sentinels to run when the command loop is
@c reading input.
$BHVJ<$O(BEmacs$B$,!J$?$H$($P!"C<KvF~NO$d;~4V7P2a!"%W%m%;%9$N=PNO$r!K(B
$BBT$C$F$$$k$H$-$K$N$_<B9T$5$l$^$9!#(B
$BB>$N(BLisp$B%W%m%0%i%`$N<B9TESCf$GL5Ca=x$KHVJ<$r<B9T$7$?>l9g$K5/$3$k(B
$B%?%$%_%s%0%(%i!<$r2sHr$9$k$?$a$G$9!#(B
@code{sit-for}$B$d(B@code{sleep-for}$B!J(B@pxref{Waiting}$B!K!"$"$k$$$O!"(B
@code{accept-process-output}$B!J(B@pxref{Accepting Output}$B!K$r(B
$B8F$S=P$9$H%W%m%0%i%`$OBT$A$KF~$j!"HVJ<$,F0$1$k$3$H$K$J$j$^$9!#(B
Emacs$B$O!"%3%^%s%I%k!<%W$GF~NO$rFI$`$H$-$K$bHVJ<$N<B9T$r5v$7$^$9!#(B

@c   Quitting is normally inhibited within a sentinel---otherwise, the
@c effect of typing @kbd{C-g} at command level or to quit a user command
@c would be unpredictable.  If you want to permit quitting inside a
@c sentinel, bind @code{inhibit-quit} to @code{nil}.  @xref{Quitting}.
$BHVJ<$NFbB&$G$OCfCG$OIaDL$O6X;_$5$l$F$$$^$9!#(B
$B$5$b$J$$$H!"%3%^%s%I%l%Y%k$GBG$C$?(B@kbd{C-g}$B$N8z2L$d!"(B
$B%f!<%6!<%3%^%s%I$rCfCG$9$k$?$a$KBG$C$?(B@kbd{C-g}$B$N8z2L$OM=B,$G$-$^$;$s!#(B
$BHVJ<$NFbB&$GCfCG$r9T$$$?$$>l9g$K$O!"(B
@code{inhibit-quit}$B$K(B@code{nil}$B$rB+G{$7$^$9!#(B
@xref{Quitting}$B!#(B

@c   A sentinel that writes the output into the buffer of the process
@c should check whether the buffer is still alive.  If it tries to insert
@c into a dead buffer, it will get an error.  If the buffer is dead,
@c @code{(buffer-name (process-buffer @var{process}))} returns @code{nil}.
$B%W%m%;%9$N%P%C%U%!$K=PNO$r=q$-9~$`HVJ<$O!"(B
$B$=$N%P%C%U%!$,M-8z$G$"$k$+$I$&$+$r8!::$9$k$Y$-$G$9!#(B
$BL58z$J%P%C%U%!$KA^F~$7$h$&$H$9$k$H%(%i!<$K$J$j$^$9!#(B
$B%P%C%U%!$,L58z$G$"$l$P!"(B
$B<0(B@code{(buffer-name (process-buffer @var{process}))}
$B$r<B9T$9$k$H(B@code{nil}$B$rJV$7$^$9!#(B

@c   If an error happens during execution of a sentinel, it is caught
@c automatically, so that it doesn't stop the execution of whatever
@c programs was running when the sentinel was started.  However, if
@c @code{debug-on-error} is non-@code{nil}, the error-catching is turned
@c off.  This makes it possible to use the Lisp debugger to debug the
@c sentinel.  @xref{Debugger}.
$BHVJ<$N<B9TCf$K%(%i!<$,H/@8$9$k$H$=$N%(%i!<$O<+F0E*$KJaB*$5$l!"(B
$BHVJ<$r;OF0$7$?$H$-$KF0$$$F$$$?(B
$B%W%m%0%i%`$N<B9T$rDd;_$7$J$$$h$&$K$7$^$9!#(B
$B$7$+$7!"(B@code{debug-on-error}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B%(%i!<$rJaB*$7$^$;$s!#(B
$B$3$l$K$h$j!"(BLisp$B%G%P%C%,$GHVJ<$r%G%P%C%0$G$-$^$9!#(B
@xref{Debugger}$B!#(B

@c   In earlier Emacs versions, every sentinel that did regular expression
@c searching or matching had to explicitly save and restore the match data.
@c Now Emacs does this automatically for sentinels; they never need to do
@c it explicitly.  @xref{Match Data}.
Emacs$B$N=i4|$NHG$G$O!"@55,I=8=$rC5:w$7$?$j0lCW=hM}$9$kHVJ<$G$O!"(B
$B%^%C%A%G!<%?$rL@<(E*$KJ]B8!?I|85$9$kI,MW$,$"$j$^$7$?!#(B
$B:#$N(BEmacs$B$O!"HVJ<$KBP$7$F$O$3$l$r<+F0E*$K9T$$$^$9$+$i!"(B
$BHVJ<$GL@<(E*$K9T$&I,MW$O$"$j$^$;$s!#(B
@xref{Match Data}$B!#(B

@defun set-process-sentinel process sentinel
@c This function associates @var{sentinel} with @var{process}.  If
@c @var{sentinel} is @code{nil}, then the process will have no sentinel.
@c The default behavior when there is no sentinel is to insert a message in
@c the process's buffer when the process status changes.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$KHVJ<(B@var{sentinel}$B$rBP1~IU$1$k!#(B
@var{sentinel}$B$,(B@code{nil}$B$G$"$k$H!"%W%m%;%9$KHVJ<$O$J$$!#(B
$BHVJ<$,$J$$>l9g$N%G%U%)%k%H$N$U$k$^$$$O!"(B
$B%W%m%;%9>uBV$,JQ2=$9$k$H%W%m%;%9$N%P%C%U%!$K%a%C%;!<%8$rA^F~$9$k!#(B

@smallexample
@group
(defun msg-me (process event)
   (princ
     (format "Process: %s had the event `%s'" process event)))
(set-process-sentinel (get-process "shell") 'msg-me)
     @result{} msg-me
@end group
@group
(kill-process (get-process "shell"))
     @print{} Process: #<process shell> had the event `killed'
     @result{} #<process shell>
@end group
@end smallexample
@end defun

@defun process-sentinel process
@c This function returns the sentinel of @var{process}, or @code{nil} if it
@c has none.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$NHVJ<$rJV$9$+!"(B
$BHVJ<$,$J$1$l$P(B@code{nil}$B$rJV$9!#(B
@end defun

@defun waiting-for-user-input-p
@c While a sentinel or filter function is running, this function returns
@c non-@code{nil} if Emacs was waiting for keyboard input from the user at
@c the time the sentinel or filter function was called, @code{nil} if it
@c was not.
$BHVJ<$d%U%#%k%?4X?t$,F0:nCf$K$3$N4X?t$r8F$S=P$9$H!"(B
$BHVJ<$d%U%#%k%?4X?t$r8F$S=P$7$?$H$-$K(BEmacs$B$,%f!<%6!<$+$i$N(B
$B%-!<%\!<%IF~NO$rBT$C$F$k$H(B@code{nil}$B0J30$rJV$7!"(B
$B$=$l0J30$G$O(B@code{nil}$B$rJV$9!#(B
@end defun

@node Transaction Queues
@c @section Transaction Queues
@section $B%H%i%s%6%/%7%g%s%-%e!<(B
@c @cindex transaction queue
@cindex $B%H%i%s%6%/%7%g%s%-%e!<(B

@c You can use a @dfn{transaction queue} to communicate with a subprocess
@c using transactions.  First use @code{tq-create} to create a transaction
@c queue communicating with a specified process.  Then you can call
@c @code{tq-enqueue} to send a transaction.
$B%H%i%s%6%/%7%g%s$rMQ$$$?%5%V%W%m%;%9$H$NDL?.$K(B
@dfn{$B%H%i%s%6%/%7%g%s%-%e!<(B}$B!J(Btransaction queue$B!K$r;H$($^$9!#(B
$B$^$:(B@code{tq-create}$B$rMQ$$$F!"(B
$B;XDj$7$?%W%m%;%9$H$NDL?.MQ%H%i%s%6%/%7%g%s%-%e!<$r:n@.$7$^$9!#(B
$B$=$7$F!"%H%i%s%6%/%7%g%s$rAw$k$?$a$K(B@code{tq-enqueue}$B$r8F$S=P$7$^$9!#(B

@defun tq-create process
@c This function creates and returns a transaction queue communicating with
@c @var{process}.  The argument @var{process} should be a subprocess
@c capable of sending and receiving streams of bytes.  It may be a child
@c process, or it may be a TCP connection to a server, possibly on another
@c machine.
$B$3$N4X?t$O!"%W%m%;%9(B@var{process}$B$H$NDL?.MQ%H%i%s%6%/%7%g%s%-%e!<$r(B
$B:n@.$7$FJV$9!#(B
$B0z?t(B@var{process}$B$O!"%P%$%H%9%H%j!<%`$rAw<u?.$G$-$k5!G=$r(B
$BM-$9$k%5%V%W%m%;%9$G$"$k$3$H!#(B
$B$D$^$j!";R%W%m%;%9$G$"$k$+!"JL$N%^%7%s>e$N2DG=@-$b$"$k(B
$B%5!<%P!<$X$N(BTCP$B@\B3$G$"$k!#(B
@end defun

@defun tq-enqueue queue question regexp closure fn
@c This function sends a transaction to queue @var{queue}.  Specifying the
@c queue has the effect of specifying the subprocess to talk to.
$B$3$N4X?t$O%-%e!<(B@var{queue}$B$K%H%i%s%6%/%7%g%s$rAw$k!#(B
$B%-%e!<$r;XDj$9$k$3$H$O!"(B
$BDL?.Aj<j$N%5%V%W%m%;%9$r;XDj$9$k8z2L$,$"$k!#(B

@c The argument @var{question} is the outgoing message that starts the
@c transaction.  The argument @var{fn} is the function to call when the
@c corresponding answer comes back; it is called with two arguments:
@c @var{closure}, and the answer received.
$B0z?t(B@var{question}$B$O!"%H%i%s%6%/%7%g%s$r;O$a$kAw=P%a%C%;!<%8$G$"$k!#(B
$B0z?t(B@var{fn}$B$O!"BP1~$9$k1~Ez$,La$C$F$-$?$H$-$K8F$S=P$94X?t$G$"$k!#(B
$B$=$N4X?t$O(B2$B$D$N0z?t!"(B@var{closure}$B$H<u$1<h$C$?1~Ez$G8F$S=P$5$l$k!#(B

@c The argument @var{regexp} is a regular expression that should match the
@c entire answer, but nothing less; that's how @code{tq-enqueue} determines
@c where the answer ends.
$B0z?t(B@var{regexp}$B$O!"(B1$B$D$N1~Ez$@$1$K0lCW$9$k@55,I=8=$G$"$k!#(B
@code{tq-enqueue}$B$,1~Ez$NKvHx$rH=Dj$9$k$?$a$K;H$&!#(B

@c The return value of @code{tq-enqueue} itself is not meaningful.
@code{tq-enqueue}$B$NLa$jCM$=$N$b$N$K0UL#$O$J$$!#(B
@end defun

@defun tq-close queue
@c Shut down transaction queue @var{queue}, waiting for all pending transactions
@c to complete, and then terminate the connection or child process.
$BL$=hM}$N%H%i%s%6%/%7%g%s$9$Y$F$,40N;$9$k$N$rBT$A!"(B
$B@\B3$d;R%W%m%;%9$r=*N;$7$F!"(B
$B%H%i%s%6%/%7%g%s%-%e!<(B@var{queue}$B$r=*$($k!#(B
@end defun

@c Transaction queues are implemented by means of a filter function.
@c @xref{Filter Functions}.
$B%H%i%s%6%/%7%g%s%-%e!<$O%U%#%k%?4X?t$rMQ$$$F<BAu$7$F$"$j$^$9!#(B
@xref{Filter Functions}$B!#(B

@node Network
@c @section Network Connections
@section $B%M%C%H%o!<%/@\B3(B
@c @cindex network connection
@cindex $B%M%C%H%o!<%/@\B3(B
@cindex TCP

@c   Emacs Lisp programs can open TCP network connections to other processes on
@c the same machine or other machines.  A network connection is handled by Lisp
@c much like a subprocess, and is represented by a process object.
@c However, the process you are communicating with is not a child of the
@c Emacs process, so you can't kill it or send it signals.  All you can do
@c is send and receive data.  @code{delete-process} closes the connection,
@c but does not kill the process at the other end; that process must decide
@c what to do about closure of the connection.
Emacs Lisp$B%W%m%0%i%`$O!"F10l%^%7%s$dJL$N%^%7%s>e$NB>$N%W%m%;%9$KBP$7$F(B
TCP$B%M%C%H%o!<%/@\B3$r3+$/$3$H$,$G$-$^$9!#(B
$B%M%C%H%o!<%/@\B3$O!"%5%V%W%m%;%9$HF1MM$K(BLisp$B$,07$$!"(B
$B%W%m%;%9%*%V%8%'%/%H$H$7$FI=8=$5$l$^$9!#(B
$B$7$+$7!"DL?.Aj<j$N%W%m%;%9$O(BEmacs$B%W%m%;%9$N;R%W%m%;%9$G$O$"$j$^$;$s$+$i!"(B
$B%-%k$7$?$j%7%0%J%k$rAw$k$3$H$O$G$-$^$;$s!#(B
$B%G!<%?$NAw<u?.$N$_$,2DG=$G$9!#(B
@code{delete-process}$B$O@\B3$rJD$8$^$9$,!"(B
$B$b$&0lJ}$NC<$N%W%m%;%9$r%-%k$7$^$;$s!#(B
$B$=$N%W%m%;%9$O!"@\B3$,JD$8$?>l9g$NF0:n$rH=CG$9$kI,MW$,$"$j$^$9!#(B

@c   You can distinguish process objects representing network connections
@c from those representing subprocesses with the @code{process-status}
@c function.  It always returns either @code{open} or @code{closed} for a
@c network connection, and it never returns either of those values for a
@c real subprocess.  @xref{Process Information}.
$B%M%C%H%o!<%/@\B3$rI=$9%W%m%;%9%*%V%8%'%/%H$H(B
$B%5%V%W%m%;%9$rI=$9%W%m%;%9%*%V%8%'%/%H$H$O!"(B
$B4X?t(B@code{process-status}$B$r;H$C$F6hJL$G$-$^$9!#(B
$B$3$N4X?t$O!"%M%C%H%o!<%/@\B3$KBP$7$F$O(B
@code{open}$B$+(B@code{closed}$B$r$D$M$KJV$7!"(B
$BK\Ev$N%5%V%W%m%;%9$KBP$7$F$O$3$l$i$N$$$:$l$NCM$b$1$C$7$FJV$7$^$;$s!#(B
@xref{Process Information}$B!#(B

@defun open-network-stream name buffer-or-name host service
@c This function opens a TCP connection for a service to a host.  It
@c returns a process object to represent the connection.
$B$3$N4X?t$O!"%[%9%H$N%5!<%P!<$KBP$9$k(BTCP$B@\B3$r3+$/!#(B
$B@\B3$rI=$9%W%m%;%9%*%V%8%'%/%H$rJV$9!#(B

@c The @var{name} argument specifies the name for the process object.  It
@c is modified as necessary to make it unique.
$B0z?t(B@var{name}$B$O!"%W%m%;%9%*%V%8%'%/%H$KIU$1$kL>A0$r;XDj$9$k!#(B
$BI,MW$K1~$8$F0l0U$K$9$k$?$a$K=$@5$5$l$k!#(B

@c The @var{buffer-or-name} argument is the buffer to associate with the
@c connection.  Output from the connection is inserted in the buffer,
@c unless you specify a filter function to handle the output.  If
@c @var{buffer-or-name} is @code{nil}, it means that the connection is not
@c associated with any buffer.
$B0z?t(B@var{buffer-or-name}$B$O!"@\B3$KBP1~IU$1$k%P%C%U%!$G$"$k!#(B
$B=PNO$r07$&%U%#%k%?4X?t$r;XDj$7$J$$8B$j!"(B
$B@\B3$+$i$N=PNO$O$=$N%P%C%U%!$KA^F~$5$l$k!#(B
@var{buffer-or-name}$B$,(B@code{nil}$B$G$"$k$H!"(B
$B@\B3$K$O%P%C%U%!$rBP1~IU$1$J$$$3$H$r0UL#$9$k!#(B

@c The arguments @var{host} and @var{service} specify where to connect to;
@c @var{host} is the host name (a string), and @var{service} is the name of
@c a defined network service (a string) or a port number (an integer).
$B0z?t(B@var{host}$B$H(B@var{service}$B$O!"@\B3@h$r;XDj$9$k!#(B
@var{host}$B$O%[%9%HL>!JJ8;zNs!K$G$"$j!"(B
@var{service}$B$ODj5A:Q$_$N%M%C%H%o!<%/%5!<%S%9!JJ8;zNs!K$+(B
$B%]!<%HHV9f!J@0?t!K$G$"$k!#(B
@end defun