OSDN Git Service

Convert release and draft pages to UTF-8.
[linuxjm/jm.git] / manual / expect / draft / man1 / expect.1
1 .\"
2 .\" Japanese Version Copyright (c) 1998 Hidefumi Yab 
3 .\"         all rights reserved.
4 .\" Translated Sat Jun 12 13:47:08 JST 1999
5 .\"         by Hidefumi Yab (yabide@da2.so-net.ne.jp)
6 .\" Updated Tue Jul  8 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
7 .\"
8 .TH EXPECT 1 "29 December 1994"
9
10 .\"O .SH NAME
11 .SH 名前
12 .\"O expect \- programmed dialogue with interactive programs, Version 5
13 expect \- 対話的なプログラムとのやりとりを自動化するプログラム, バージョン 5
14
15
16 .\"O .SH SYNOPSIS
17 .SH 書式
18
19 .B expect
20 [
21 .B \-dDinN
22 ]
23 [
24 .B \-c
25 .I cmds
26 ]
27 [
28 .BR \- [ f | b ]
29 ]
30 .I cmdfile
31 ]
32 [
33 .I args
34 ]
35
36 .\"O .SH INTRODUCTION
37 .SH イントロダクション
38 .\"O .B Expect
39 .\"O is a program that "talks" to other interactive programs according to a
40 .\"O script.  Following the script,
41 .\"O .B Expect
42 .\"O knows what can be expected from
43 .\"O a program and what the correct response should be.  An interpreted
44 .\"O language provides branching and high-level control structures to
45 .\"O direct the dialogue.  In addition, the user can take control
46 .\"O and interact directly when desired, afterward returning control to the
47 .\"O script.
48 .B Expect
49 は、スクリプトの指示に従って、対話的なプログラムと"会話"するプログラムである。
50 以下のスクリプトに示すように、
51 .B Expect
52 には、対話プログラムからの期待されうる入力とそれに対する正しい応答を
53 教えておく。インタプリタは分岐処理と高度な制御構造を提供し、
54 対話プログラムへの指示を行なう。
55 さらに、必要な時にスクリプトから制御を奪って直接人間が指示を行ない、
56 その後、制御をスクリプトへ戻すことができる。
57
58 .PP
59 .\"O .B Expectk
60 .\"O is a mixture of
61 .\"O .B Expect
62 .\"O and
63 .\"O .BR Tk .
64 .\"O It behaves just like
65 .\"O .B Expect
66 .\"O and
67 .\"O .BR Tk 's
68 .\"O .BR wish .
69 .\"O .B Expect
70 .\"O can also be used directly in C or C++ (that is, without Tcl).
71 .\"O See libexpect(3).
72 .B Expectk
73
74 .B Expect
75
76 .BR Tk
77 の混合物である。
78 .B Expect
79 であり、かつ、
80 .BR Tk 's
81 .BR wish
82 であるかのように振舞う。
83 .B Expect
84 は、C あるいは C++ (つまり、Tcl 以外)から、直接使うこともできる。
85 libexpect(3)を参照。
86 .PP
87 .\"O The name "Expect" comes from the idea of
88 .\"O .I send/expect
89 .\"O sequences popularized
90 .\"O by uucp, kermit and other modem control programs.
91 .\"O However unlike uucp,
92 .\"O .B Expect
93 .\"O is generalized so that it can be run as a user-level command
94 .\"O with any program and task in mind.
95 .\"O .B Expect
96 .\"O can actually talk to several programs at the same time.
97 "Expect"という名前は、uucpで有名になった
98 .I send/expect
99 の概念に由来する。
100 (kermitや他のモデム制御プログラムでも、この概念は使われている)
101 しかし、uucp とは違って
102 .B Expect
103 は一般化されているので、想像されるどんなプログラムやタスクに対しても
104 マクロコマンド(user-level command)として機能できる。
105 .B Expect
106 は、同時に複数のプログラムと会話することができる。
107 .PP
108 .\"O For example, here are some things
109 .\"O .B Expect
110 .\"O can do:
111 .\"O .RS
112 .\"O .TP 4
113 .\"O \(bu
114 .\"O Cause your computer to dial you back,
115 .\"O so that you can login without paying for the call.
116 .\"O .TP
117 .\"O \(bu
118 .\"O Start a game (e.g., rogue) and if the optimal configuration doesn't appear,
119 .\"O restart it (again and again) until it does,
120 .\"O then hand over control to you.
121 .\"O .TP
122 .\"O \(bu
123 .\"O Run fsck, and in response to its questions, answer "yes", "no" or give control back to you,
124 .\"O based on predetermined criteria.
125 .\"O .TP
126 .\"O \(bu
127 .\"O Connect to another network or BBS (e.g., MCI Mail, CompuServe) and
128 .\"O automatically retrieve your mail so that it appears as if
129 .\"O it was originally sent to your local system.
130 .\"O .TP
131 .\"O \(bu
132 .\"O Carry environment variables, current directory,
133 .\"O or any kind of information across rlogin, telnet, tip, su, chgrp, etc.
134 .\"O .RE
135 .B Expect
136 にできることの例をいくつか挙げておく:
137 .RS
138 .TP 4
139 \(bu
140 電話代を払わずにログインできるようにコンピュータからあなたに電話を掛け直させる。
141 .TP
142 \(bu
143 ゲーム(例えば rogue)を始める時に、最適なパラメタがもらえなかった場合
144 最適なパラメタがもらえるまで何度でもリスタートを行ない、その後制御を人間に移す。
145 .TP
146 \(bu
147 fsckを走らせた時に現れる質問に、前もって決めておいた方針に従って、
148 "yes", "no", "手入力"を切替えて、返答する。
149 .TP
150 \(bu
151 他のネットワークや BBS(例えばMCI Mail, CompuServe)に接続した時に
152 自動的にメールの取り込み、発信を行なう。
153 .TP
154 \(bu
155 環境変数、カレントディレクトリ、その他の情報を、rlogin, telnet, tip, su, \
156  chgrp などを行なった先へ持っていく。
157 .RE
158 .PP
159 .\"O There are a variety of reasons why the shell cannot perform these tasks.
160 .\"O (Try, you'll see.)
161 .\"O All are possible with
162 .\"O .BR Expect .
163 これらの処理をシェルが行なえない理由はたくさんある
164 (やってみればわかるだろう)。全部
165 .BR Expect
166 ならできる。
167 .PP
168 .\"O In general,
169 .\"O .B Expect
170 .\"O is useful for running any program which requires
171 .\"O interaction between the program and the user.
172 .\"O All that is necessary is that the interaction can be characterized
173 .\"O programmatically.
174 .\"O .B Expect
175 .\"O can also give the user back control
176 .\"O (without halting the program being controlled) if desired.
177 .\"O Similarly, the user can return control to the script at any time.
178 一般に
179 .B Expect
180 は、プログラムとユーザーのやりとりが必要なプログラムを走らせるときに
181 役に立つ。大事なことは、このやりとりがプログラムの性格を持っていると
182 いうことである。
183 .B Expect
184 は、必要ならユーザーに制御を返すこともできる(しかも、プログラムは
185 中断されない)。同様に、ユーザーは制御をいつでもスクリプトに返すことができる。
186
187 .\"O .SH USAGE
188 .SH 用法
189 .\"O .B Expect
190 .\"O reads
191 .\"O .I cmdfile
192 .\"O for a list of commands to execute.
193 .\"O .B Expect
194 .\"O may also be invoked implicitly on systems which support the #! notation
195 .\"O by marking the script executable, and making the first line in your script:
196 .\"O 
197 .\"O     #!/usr/local/bin/expect \-f
198 .\"O 
199 .\"O Of course, the path must accurately describe where
200 .\"O .B Expect
201 .\"O lives.  /usr/local/bin is just an example.
202 .\"O 
203 .\"O The
204 .\"O .B \-c
205 .\"O flag prefaces a command to be executed before any in the script.
206 .\"O The command should be quoted to prevent being broken up by the shell.
207 .\"O This option may be used multiple times.
208 .\"O Multiple commands may be
209 .\"O executed with a single
210 .\"O .B \-c
211 .\"O by separating them with semicolons.
212 .\"O Commands are executed in the order they appear.  
213 .\"O (When using Expectk, this option is specified as
214 .\"O .BR \-command .)
215 .\"O
216 .B Expect
217 は、
218 .I cmdfile
219 を読み込み、実行するコマンドのリストを得る。
220 .B Expect
221 は、#! 表記をサポートする OS で、先頭行に
222
223     #!/usr/local/bin/expect \-f
224
225 と書いておいて実行させることもできる。
226 もちろん、パスは正確に
227 .B Expect
228 のある場所を指示していなければならない。
229 /usr/local/bin は、一例である。
230
231 .B \-c
232 フラグで、スクリプトを実行する前に、実行するコマンドを指示する。
233 コマンドはシェルに壊されないようにクオートしておくべきである。
234 このオプションは何回出てきても構わない。
235 複数コマンドを指示した場合は、セミコロンで連結されたコマンドのように
236 扱われる。
237 コマンドは現れた順に実行される。(Expectk では、
238 .BR \-command
239 と書く)
240 .PP
241 .\"O The
242 .\"O .B \-d
243 .\"O flag enables some diagnostic output, which
244 .\"O primarily reports internal activity of commands such as 
245 .\"O .B expect
246 .\"O and
247 .\"O .BR interact .
248 .\"O This flag has the same effect as "exp_internal 1" at the beginning of an Expect
249 .\"O script, plus the version of
250 .\"O .B Expect
251 .\"O is printed.
252 .\"O (The
253 .\"O .B strace
254 .\"O command is useful for tracing statements, and the
255 .\"O .B trace
256 .\"O command is useful for tracing variable assignments.)
257 .\"O (When using Expectk, this option is specified as
258 .\"O .BR \-diag .)
259 .B \-d
260 フラグで、デバッグ情報出力を有効にする。基本的に
261 内部のコマンド(例えば
262 .B expect
263
264 .BR interact )
265 の振舞いを報告する。
266 このフラグは"exp_internal 1"とスクリプトの先頭に書くのと同じことだが、
267 さらに
268 .B Expect
269 のバージョン番号も出力される。
270 (
271 .B strace
272 コマンドは、命令をトレースするのに便利である。
273 .B trace
274 コマンドは、変数値をトレースするのに便利である。)
275 (Expectk を使う時は、このオプションは
276 .BR \-diag
277 と書く。)
278 .PP
279 .\"O The
280 .\"O .B \-D
281 .\"O flag enables an interactive debugger.  An integer value should follow.
282 .\"O The debugger will take control before the next Tcl procedure
283 .\"O if the value is non-zero
284 .\"O or if a ^C is pressed (or a breakpoint is hit, or other appropriate debugger
285 .\"O command appears in the script).  See the README file or SEE ALSO (below)
286 .\"O for more information on the debugger.
287 .\"O (When using Expectk, this option is specified as
288 .\"O .BR \-Debug .)
289 .B \-D
290 フラグで対話型デバッガを有効にする。整数値が続かなければならない。
291 値が 0 でないか、C が押されると、次の Tcl 処理の前でデバッガに制御が移る。
292 ブレークポイントにかかった時や他のデバッグ命令を実行した時も、同じである。
293 デバッガについての情報がもっと欲しければ、 README や下記の関連項目を読むこと。
294 (Expectk を使っている時は、このオプションは
295 .BR \-Debug )
296 .PP
297 .\"O The
298 .\"O .B \-f
299 .\"O flag prefaces a file from which to read commands from.
300 .\"O The flag itself is optional as it is only useful when using
301 .\"O the #! notation (see above),
302 .\"O so that other arguments may be supplied on the command line.
303 .\"O (When using Expectk, this option is specified as
304 .\"O .BR \-file .)
305 .B \-f
306 フラグで、コマンドを読んでくるファイルを指示する。このフラグは
307 あってもなくても良いのだが、#! 表記と一緒に使うと
308 引数からプログラム名を除けるから、その場合意味がある。
309 (Expectk では
310 .BR \-file )
311 .PP
312 .\"O By default, the command file is read into memory and executed in its entirety.
313 .\"O It is occasionally desirable to read files one line at a time.  For example,
314 .\"O stdin is read this way.  In order to force arbitrary files to be handled this
315 .\"O way, use the
316 .\"O .B \-b
317 .\"O flag.
318 .\"O (When using Expectk, this option is specified as
319 .\"O .BR \-buffer .)  Note that stdio-buffering may still take place however this shouldn't cause problems when reading from a fifo or stdin.
320 デフォルトでは、コマンドファイルがメモリに一度に読み込まれ、そこで実行される。
321 一行ずつコマンドファイルを読んだ方が望ましい場合もある。例えば、
322 標準入力はこのように扱った方が良い。強制的にこのモードを指定するには、
323 .B \-b
324 フラグを指定する。
325 (Expectkでは、
326 .BR \-buffer )
327 stdio のバッファリングは依然有効であるが、FIFO または stdin から読み込む場合は
328 問題は起こらないはずであることに注意すること。
329 .PP
330 .\"O If the string "\-" is supplied as a filename, standard input is read instead.
331 .\"O (Use "./\-" to read from a file actually named "\-".)
332 "\-"がファイル名として渡されると、標準入力からスクリプトが読み込まれる。
333 (本当に"\-"と言うファイルが読みたければ、"./\-"と書くこと)
334 .PP
335 .\"O The
336 .\"O .B \-i
337 .\"O flag causes
338 .\"O .B Expect
339 .\"O to interactively prompt for commands instead of reading
340 .\"O them from a file.
341 .\"O Prompting is terminated via the
342 .\"O .B exit
343 .\"O command or upon EOF.
344 .\"O See
345 .\"O .B interpreter
346 .\"O (below) for more information.
347 .\"O .B \-i
348 .\"O is assumed if neither a command file nor
349 .\"O .B \-c
350 .\"O is used.
351 .\"O (When using Expectk, this option is specified as
352 .\"O .BR \-interactive .)
353 .B \-i
354 フラグを指示すると、
355 .B Expect
356 はファイルからスクリプトを読まずに対話用プロンプトを表示する。
357 .B exit
358 コマンドか、EOF を受けるとシェルを終了する。
359 詳細については
360 .B interpreter
361 (下記) を参照のこと。
362 .B \-i
363 を指定した場合には、
364 コマンドファイルも
365 .B \-c
366 も指示されなかったものとして実行される。
367 (Expectkでは
368 .BR \-interactive )
369 .PP
370 .\"O .B \-\-
371 .\"O may be used to delimit the end of the options.  This is useful if
372 .\"O you want to pass an option-like argument to your script without it being
373 .\"O interpreted by
374 .\"O .BR Expect .
375 .\"O This can usefully be placed in the #! line to prevent any flag-like
376 .\"O interpretation by Expect.  For example, the following will leave the
377 .\"O original arguments (including the script name) in the variable
378 .\"O .IR argv .
379 .\"O 
380 .\"O     #!/usr/local/bin/expect \-\-
381 .\"O 
382 .\"O Note that the usual getopt(3) and execve(2) conventions must be observed
383 .\"O when adding arguments to the #! line.
384 .B \-\-
385 は、オプションの終りを区切るのに用いられる(省略可能)。これは、あなたが
386 オプションタイプの引数を
387 .BR Expect
388 に解釈させないで、スクリプトにそのまま渡したい時に役に立つ。
389 #! 行にこれを置いて、Expect にオプションとして解釈させないようにするこ
390 とができて便利た。
391
392 例えば、以下のように書くと(スクリプト名も含めて)オリジナルの引数は、変数
393 .IR argv
394 に残される。
395
396     #!/usr/local/bin/expect \-\-
397
398 #!行に引数を加えると、通常の getopt(3) や execve(2) ではその引数が見えてしまう
399 ことに注意すること。
400 .PP
401 .\"O The file $exp_library/expect.rc is sourced automatically if present, unless
402 .\"O the
403 .\"O .B \-N
404 .\"O flag is used.  
405 .\"O (When using Expectk, this option is specified as
406 .\"O .BR \-NORC .)
407 .\"O Immediately after this,
408 .\"O the file ~/.expect.rc is sourced automatically, unless the
409 .\"O .B \-n
410 .\"O flag is used.  If the environment variable DOTDIR is defined,
411 .\"O it is treated as a directory and .expect.rc is read from there.
412 .\"O (When using Expectk, this option is specified as
413 .\"O .BR \-norc .)
414 .\"O This sourcing occurs only after executing any
415 .\"O .B \-c
416 .\"O flags.
417 .B \-N
418 フラグを用いない限り、ファイル $exp_library/expect.rc が(あれば)自動的に
419 実行される。
420 (Expectk では、
421 .BR \-NORC )
422 .B \-n
423 フラグ
424 (Expectk では、
425 .BR \-norc )
426 を用いない限り、
427 続いて、ファイル ~/.expect.rc が、自動的に実行される。
428 環境変数 DOTDIR が定義されていれば、そこが .expect.rc のあるディレクトリ
429 として扱われる。
430
431 この二つのrcファイルの実行より先に
432 .B \-c
433 フラグで指示されたコマンドが実行される。
434 .PP
435 .\"O .B \-v
436 .\"O causes Expect to print its version number and exit.  (The corresponding flag
437 .\"O in Expectk, which uses long flag names, is \-version.)
438 .B \-v
439 フラグを指示すると、バージョン番号を表示して終了する。
440 (Expectkでは、\-version)
441 .PP
442 .\"O Optional
443 .\"O .I args
444 .\"O are constructed into a list and stored in the variable named
445 .\"O .IR argv .
446 .\"O .I argc
447 .\"O is initialized to the length of argv.
448 オプション
449 .I args
450 は、リストに変換されて、変数
451 .IR argv
452 に保存される。
453 .I argc
454 は、argv のリスト長(要素の数)に設定される。
455 .PP
456 .\"O .I argv0
457 .\"O is defined to be the name of the script (or binary if no script is used).
458 .\"O For example,
459 .\"O the following prints out the name of the script and the first three arguments:
460 .I argv0
461 は、スクリプト名に設定される(スクリプトを使っていなければ、
462 バイナリの名前になる)。
463 例えば、以下のスクリプトを実行すると、スクリプト名と最初の引数3つを表示する:
464 .nf
465
466     send_user "$argv0 [lrange $argv 0 2]\\n"
467
468 .fi
469 .\"O .SH COMMANDS
470 .SH コマンド
471 .\"O .B Expect
472 .\"O uses
473 .\"O .I Tcl
474 .\"O (Tool Command Language).
475 .\"O Tcl provides control flow (e.g., if, for, break),
476 .\"O expression evaluation and several other features such as recursion,
477 .\"O procedure definition, etc.
478 .\"O Commands used here but not defined (e.g.,
479 .\"O .BR set ,
480 .\"O .BR if ,
481 .\"O .BR exec )
482 .\"O are Tcl commands (see tcl(3)).
483 .\"O .B Expect
484 .\"O supports additional commands, described below.
485 .\"O Unless otherwise specified, commands return the empty string.
486 .\"O
487 .B Expect
488 は、
489 .I Tcl
490 (Tool Command Language)を使用している。
491 Tcl は、制御フロー(例えば if, for, break)、式評価、および、
492 再帰やプロシジャ定義等他のいくつかの機能を提供する。
493 ここで使われているのに定義がないコマンド(例えば、
494 .BR set ,
495 .BR if ,
496 .BR exec )
497 は、Tcl コマンドである。(tcl(3)を参照)。
498 .B Expect
499 は、以下に記述する追加コマンドをサポートする。
500 記述がない場合は、そのコマンドは空文字列を返す。
501 .PP
502 .\"O Commands are listed alphabetically so that they can be quickly located.
503 .\"O However, new users may find it easier to start by reading the descriptions
504 .\"O of
505 .\"O .BR spawn ,
506 .\"O .BR send ,
507 .\"O .BR expect ,
508 .\"O and
509 .\"O .BR interact ,
510 .\"O in that order.
511 .\"O 
512 .\"O Note that the best introduction to the language (both Expect and Tcl)
513 .\"O is provided in the book "Exploring Expect" (see SEE ALSO below).
514 .\"O Examples are included in this man page but they are very limited since
515 .\"O this man page is meant primarily as reference material.
516 .\"O 
517 .\"O Note that in the text of this man page, "Expect" with an uppercase "E"
518 .\"O refers to the
519 .\"O .B Expect
520 .\"O program while "expect" with a lower-case "e" refers to the
521 .\"O .B expect
522 .\"O command within the
523 .\"O .B Expect
524 .\"O program.)
525 コマンドはアルファベットの列なのですぐにわかると思うが、
526 新しいユーザーは、
527 .BR spawn ,
528 .BR send ,
529 .BR expect ,
530 .BR interact ,
531 が、この順で並んでいるところを読み始めた方が理解しやすいと
532 気がつくかも知れない。
533
534 この言語(Expect と Tcl の両方)へのイントロダクションとしては、
535 "Exploring Expect"という本(関連項目を参照)がベストである。
536 このマニュアルページはリファレンスとして書いているので、
537 含まれている例は非常に限られている。注意すること。
538
539 このマニュアルページで、大文字の"E"で"Expect"とあれば、それは、
540 .B Expect
541 プログラムを指し、一方小文字の"e"で"expect"とあれば、それは、
542 .B Expect
543 プログラムに実装されている
544 .B expect
545 コマンドを指す。注意すること。
546 .I
547 .TP 6
548 .BI close " [-slave] [\-onexec 0|1] [\-i spawn_id]"
549 .\"O closes the connection to the current process.
550 .\"O Most interactive programs will detect EOF on their stdin and exit;
551 .\"O thus
552 .\"O .B close
553 .\"O usually suffices to kill the process as well.
554 .\"O The
555 .\"O .B \-i
556 .\"O flag declares the process to close corresponding to the named spawn_id.
557 .\"O 
558 .\"O Both
559 .\"O .B expect
560 .\"O and
561 .\"O .B interact
562 .\"O will detect when the current process exits and implicitly do a
563 .\"O .BR close .
564 .\"O But if you kill the process by, say, "exec kill $pid",
565 .\"O you will need to explicitly call
566 .\"O .BR close .
567 .\"O 
568 .\"O The
569 .\"O .BR \-onexec
570 .\"O flag determines whether the spawn id will be closed in any new spawned
571 .\"O processes or if the process is overlayed.  To leave a spawn id open,
572 .\"O use the value 0.  A non-zero integer value will force the spawn closed
573 .\"O (the default) in any new processes.
574 .\"O 
575 .\"O The 
576 .\"O .B \-slave
577 .\"O flag closes the slave associated with the spawn id.  (See "spawn -pty".)
578 .\"O When the connection is closed, the slave is automatically closed as
579 .\"O well if still open.
580 .\"O 
581 .\"O No matter whether the connection is closed implicitly or explicitly,
582 .\"O you should call
583 .\"O .B wait
584 .\"O to clear up the corresponding kernel process slot.
585 .\"O .B close
586 .\"O does not call
587 .\"O .B wait
588 .\"O since there is no guarantee that closing a process connection will cause
589 .\"O it to exit.
590 .\"O See
591 .\"O .B wait
592 .\"O below for more info.
593 カレントプロセスへのコネクションをクローズする。
594 ほとんどの対話型プログラムが標準入力の EOF を検出し exit する。
595 それゆえ、
596 .B close
597 はそのプロセスを kill するのにも通常充分である。
598 .B \-i
599 フラグを指示すると、続く spawn_id を持つプロセスをクローズする。
600
601 .B expect
602
603 .B interact
604 は両方とも、カレントプロセスが exit した時点を検出して、明示しなくても
605 .BR close
606 を実行する。
607 しかし、"exec kill $pid" などのように、あなたがプロセスを kill している
608 なら、明示的に
609 .BR close
610 を呼ぶ必要がある。
611
612 .BR \-onexec
613 フラグを指示すると、新しい spawn が起きた時またはプロセスが重ねられた時に
614 前の spawn を閉じるべきかどうかを指示することができる。
615 前の spawn id で開いたままにしておきたければ、値 0 を用いる。
616 0 でない整数を指示すると、新しいプロセス中では前の spawn はクローズされる
617 (デフォルト)。
618
619 .B \-slave
620 フラグを指示すると、その spawn id の抱えているスレーブの spawn もクローズする。
621 ("spawn -pty"を参照)
622 コネクションがクローズされると、スレーブはオープン状態であっても
623 クローズされる。
624
625 コネクションのクローズが明示されていたか否かに全然関わりなく、
626 関係するカーネルプロセススロットをクリアしてしまいたければ、
627 .B wait
628 を呼ぶこと。
629 .B close
630 は、
631 .B wait
632 を呼ばない。プロセスへのコネクションをクローズすると、そのプロセスが
633 exit するという保証がないからである。
634 もっと知りたければ、
635 .B wait
636 の項を参照すること。
637 .TP
638 .BI debug " [[-now] 0|1]"
639 .\"O controls a Tcl debugger allowing you to step through statements, set
640 .\"O breakpoints, etc.
641 .\"O 
642 .\"O With no arguments, a 1 is returned if the debugger is not running, otherwise
643 .\"O a 0 is returned.
644 .\"O 
645 .\"O With a 1 argument, the debugger is started.  With a 0 argument, the
646 .\"O debugger is stopped.  If a 1 argument is preceded by the
647 .\"O .B \-now
648 .\"O flag, the debugger is started immediately (i.e., in the middle of the
649 .\"O .B debug
650 .\"O command itself).  Otherwise, the debugger is started with the next
651 .\"O Tcl statement.
652 .\"O 
653 .\"O The
654 .\"O .B debug
655 .\"O command does not change any traps.  Compare this to starting Expect with the 
656 .\"O .B -D
657 .\"O flag (see above).
658 .\"O 
659 .\"O See the README file or SEE ALSO (below)
660 .\"O for more information on the debugger.
661 は、Tcl デバッガを制御する。デバッガにより、ステップ実行、ブレークポイントの
662 設定などが行なえる。
663
664 引数がない場合、デバッガが走っていれば 1 を、そうでなければ 0 を返す。
665
666 引数が 1 なら、デバッガが起動される。引数が 0 なら、デバッガが停止する。
667 引数 1 の前に
668 .B \-now
669 フラグがあれば、デバッガは即座に起動される(つまり、
670 .B debug
671 コマンドそのものの途中で)。そうでなければ、デバッガは次の Tcl コマンドから
672 起動される。
673
674 .B debug
675 コマンドはトラップを変更しない。
676 .B -D
677 フラグをつけて起動させた場合とはそこが違う(上記参照)。
678
679 デバッガについては、README ファイルと関連項目を参照すること。
680 .TP
681 .B disconnect
682 .\"O disconnects a forked process from the terminal.  It continues running in the
683 .\"O background.  The process is given its own process group (if possible).
684 .\"O Standard I/O is redirected to /dev/null.
685 fork されたプロセスを端末から切り離す。バックグラウンドで動作は続く。
686 プロセスは可能であれば自分自身のプロセスグループを与える。
687 標準入出力は、/dev/null にリダイレクトされる。
688 .IP
689 .\"O The following fragment uses
690 .\"O .B disconnect
691 .\"O to continue running the script in the background.  
692 以下の断片は、
693 .B disconnect
694 を使って、バックグラウンドでスクリプトの実行を続ける。
695 .nf
696
697     if {[fork]!=0} exit
698     disconnect
699     . . .
700
701 .fi
702 .\"O The following script reads a password, and then runs a program
703 .\"O every hour that demands a password each time it is run.  The script supplies
704 .\"O the password so that you only have to type it once.
705 .\"O (See the
706 .\"O .B stty
707 .\"O command which demonstrates how to turn off password echoing.)
708 以下のスクリプトは、パスワードを読んで、一時間毎にパスワードを要求する
709 プログラムを実行する。スクリプトはパスワードを読み込んでいるので、
710 タイプするのは一回だけで済む。
711 (パスワードのエコーを避ける方法については、
712 .B stty
713 コマンドを参照)
714 .nf
715     send_user "password?\\ "
716     expect_user -re "(.*)\\n"
717     for {} 1 {} {
718         if {[fork]!=0} {sleep 3600;continue}
719         disconnect
720         spawn priv_prog
721         expect Password:
722         send "$expect_out(1,string)\\r"
723         . . .
724         exit
725     }
726
727 .fi
728 .\"O An advantage to using
729 .\"O .B disconnect
730 .\"O over the shell asynchronous process feature (&) is that
731 .\"O .B Expect
732 .\"O can
733 .\"O save the terminal parameters prior to disconnection, and then later
734 .\"O apply them to new ptys.  With &,
735 .\"O .B Expect
736 .\"O does not have a chance
737 .\"O to read the terminal's parameters since the terminal is already
738 .\"O disconnected by the time
739 .\"O .B Expect
740 .\"O receives control.
741 シェルの非同期実行(&)時に
742 .B disconnect
743 を用いる利点は、
744 .B Expect
745 が disconnect の前に端末情報を保存しておいて、後で新しい pty にそのパラメタを
746 適用できる点にある。
747 & を使っていて
748 .B Expect
749 が制御を受けとって disconnect されてしまうと、端末情報を読み込むことはできない。
750 .TP
751 .BI exit " [\-opts] [status]"
752 .\"O causes
753 .\"O .B Expect
754 .\"O to exit or otherwise prepare to do so.
755 .\"O 
756 .\"O The
757 .\"O .B \-onexit
758 .\"O flag causes the next argument to be used as an exit handler.
759 .\"O Without an argument, the current exit handler is returned.
760 .\"O 
761 .\"O The
762 .\"O .B \-noexit
763 .\"O flag causes
764 .\"O .B Expect
765 .\"O to prepare to exit but stop short of actually returning control to the
766 .\"O operating system.  The user-defined exit handler is run as well as Expect's
767 .\"O own internal handlers.
768 .\"O No further Expect commands should be executed.
769 .\"O This is useful if you are running Expect with other Tcl extensions.
770 .\"O The current interpreter (and main window if in the Tk environment) remain
771 .\"O so that other Tcl extensions can clean up.  If Expect's
772 .\"O .B exit
773 .\"O is called again (however this might occur), the handlers are not rerun.
774 .\"O 
775 .\"O Upon exiting, 
776 .\"O all connections to spawned processes are closed.  Closure will be detected
777 .\"O as an EOF by spawned processes.
778 .\"O .B exit
779 .\"O takes no other actions beyond what the normal _exit(2) procedure does.
780 .\"O Thus, spawned processes that do not check for EOF may continue to run.
781 .\"O (A variety of conditions are important to determining, for example, what
782 .\"O signals a spawned process will be sent, but these are system-dependent,
783 .\"O typically documented under exit(3).)
784 .\"O Spawned processes that continue to run will be inherited by init.
785 .\"O 
786 .\"O .I status
787 .\"O (or 0 if not specified) is returned as the exit status of
788 .\"O .BR Expect .
789 .\"O .B exit
790 .\"O is implicitly executed if the end of the script is reached.
791 .B Expect
792 を exit させるか、そのための準備を行なう。
793
794 .B \-onexit
795 フラグは、続く引数を exit ハンドラとして用いる。
796 引数がなければ、exit ハンドラは何もしない。
797
798 .B \-noexit
799 フラグを指定すると
800 .B Expect
801 は、exit の準備をして OS へ制御を返す直前に停止する。
802 ユーザーの定義した exit ハンドラは、Expect 自身の内部ハンドラと同じように
803 実行される。
804 それ以上 Expect のコマンドが実行されるべきではない。あなたが他の
805 Tcl Extension を Expect につけている場合にこの機能は意味がある。
806 Expect の
807 .B exit
808 がもう一度呼び出されると(こういう場合も起こり得る)、ハンドラは処理を
809 返さない。
810
811 exit する際に、全ての spawn されたプロセスへのコネクションはクローズされる。
812 クローズは EOF 検出によって行なわれる。
813 .B exit
814 は、普通の exit(2) が行なう以上のことはしない。
815 それで、spawn されたプロセスが EOF をチェックしない場合、そのプロセスは
816 走り続ける。(spawn されたプロセスへ送られたシグナルを判断するといったこと
817 には複数の条件が関わってくる。これらは、システム依存であり、典型的な動作は
818 各システムの exit(3) のドキュメントに記述されている。)
819
820 .I status
821 (指定がないときは、0 )は、
822 .BR Expect
823 の、終了ステータスとしてシステムに返される。
824 .B exit
825 は、スクリプトの終りに達すると、書いていなくても実行される、
826 .TP
827 \fBexp_continue\fR [-continue_timer]
828 .\"O The command
829 .\"O .B exp_continue
830 .\"O allows
831 .\"O .B expect
832 .\"O itself to continue
833 .\"O executing rather than returning as it normally would. By
834 .\"O default
835 .\"O .B exp_continue
836 .\"O resets the timeout timer. The
837 .\"O .I -continue_timer
838 .\"O flag prevents timer from being restarted. (See
839 .\"O .B expect
840 .\"O for more information.)
841 .B exp_continue
842 コマンドは
843 .B expect
844 自身に待っていた値が来なかった時のように、expect の実行を続ける。
845 デフォルトでは
846 .B exp_continue
847 は時間切れタイマーをリセットする。
848 .I -continue_timer
849 フラグはタイマーを再実行しないようにする。
850 (より詳細な情報は
851 .B expect
852 を参照のこと。)
853 .TP
854 .BI exp_internal " [\-f file] value"
855 .\"O causes further commands to send diagnostic information internal to
856 .\"O .B Expect
857 .\"O to stderr if
858 .\"O .I value
859 .\"O is non-zero.  This output is disabled if
860 .\"O .I value
861 .\"O is 0.  The diagnostic information includes every character received,
862 .\"O and every attempt made to match the current output against the patterns.
863 .I value
864 がゼロでなければ、以降のコマンドの診断情報を
865 .B Expect
866 内部の stderr に送るようになる。
867 .I value
868 に0を指定するとこの出力は止まる。この診断情報には、受けとった
869 すべての文字と、現在の出力とパターンをマッチさせる全試行が
870 含まれる。
871 .IP
872 .\"O If the optional
873 .\"O .I file
874 .\"O is supplied, all normal and debugging output is written to that file
875 .\"O (regardless of the value of
876 .\"O .IR value ).
877 .\"O Any previous diagnostic output file is closed.
878 .\"O 
879 .\"O The
880 .\"O .B \-info
881 .\"O flag causes exp_internal to return a description of the
882 .\"O most recent non-info arguments given.
883 .I file
884 オプションを指定すると、すべての通常および診断出力がそのファイルに
885 出力される。(
886 .IR value
887 の値とは無関係に)。すでにオープンされている診断出力ファイルは、
888 すべてクローズされる。
889
890 .B \-info
891 フラグは、最後に指定された info フラグでない引数の内容を返す。
892 .TP
893 .BI exp_open " [args] [\-i spawn_id]"
894 .\"O returns a Tcl file identifier that corresponds to the original spawn id.
895 .\"O The file identifier can then be used as if it were opened by Tcl's
896 .\"O .B open
897 .\"O command.  (The spawn id should no longer be used.  A
898 .\"O .B wait
899 .\"O should not be executed.
900 .\"O 
901 .\"O The
902 .\"O .B \-leaveopen
903 .\"O flag leaves the spawn id open for access through 
904 .\"O Expect commands.  A
905 .\"O .B wait
906 .\"O must be executed on the spawn id.
907 元の spawn id に結びつけられたファイル ID を返す。
908 そのファイル ID は、Tcl の
909 .B open
910 コマンドでオープンした時と同様に扱える。
911 (spawn id は、もう使われるべきでない。
912 .B wait
913 も実行すべきではない。)
914
915 .B \-leaveopen
916 フラグは、spawn id をオープンしたままにしておく。
917 .B wait
918 が、その spawn id に対して実行されねばならない。
919 .TP
920 .BI exp_pid " [\-i spawn_id]"
921 .\"O returns the process id corresponding to the currently spawned process.
922 .\"O If the
923 .\"O .B \-i
924 .\"O flag is used, the pid returned corresponds to that of the given spawn id.
925 現在の spawn されたプロセスのプロセス ID を返す。
926 .B \-i
927 フラグを指示すると、与えられた spawn id に対するプロセスの ID を返す。
928 .TP
929 .B exp_send
930 .\"O is an alias for
931 .\"O .BR send .
932 .BR send
933 のエイリアス。
934 .TP
935 .B exp_send_error
936 .\"O is an alias for
937 .\"O .BR send_error .
938 .BR send_error
939 のエイリアス。
940 .TP
941 .B exp_send_log
942 .\"O is an alias for
943 .\"O .BR send_log .
944 .BR send_log
945 のエイリアス。
946 .TP
947 .B exp_send_tty
948 .\"O is an alias for
949 .\"O .BR send_tty .
950 .BR send_tty
951 のエイリアス。
952 .TP
953 .B exp_send_user
954 .\"O is an alias for
955 .\"O .BR send_user .
956 .BR send_user
957 のエイリアス。
958 .TP
959 .BI exp_version " [[\-exit] version]"
960 .\"O is useful for assuring that the script is compatible with the current
961 .\"O version of Expect.
962 .\"O .IP
963 .\"O With no arguments, the current version of
964 .\"O .B Expect
965 .\"O is returned.  This version
966 .\"O may then be encoded in your script.  If you actually know that you are not
967 .\"O using features of recent versions, you can specify an earlier version.
968 は、スクリプトが現バージョンのExpectで動くことを確かめる時に役に立つ。
969 .IP
970 引数がなければ、
971 .B Expect
972 の現在のバージョンを返す。このバージョンはあなたのスクリプト内で
973 設定しても良い。あなたが最近のバージョンに入った機能を使わないの
974 であれば、もっと前のバージョンを指定することができる。
975 .IP
976 .\"O Versions consist of three numbers separated by dots.  First
977 .\"O is the major number.  Scripts written for versions of
978 .\"O .B Expect
979 .\"O with a
980 .\"O different major number will almost certainly not work.
981 .\"O .B exp_version 
982 .\"O returns an error if the major numbers do not match.
983 バージョンはドットで区切られた 3 つの番号である。
984 最初の番号は、メジャー番号である。
985 違うメジャー番号の
986 .B Expect
987 用に書いたスクリプトは、まず動かない。
988 .B exp_version 
989 は、メジャー番号がマッチしないとエラーを返す。
990 .IP
991 .\"O Second is the minor number.  Scripts written for a version with a
992 .\"O greater minor number than the current version
993 .\"O may depend upon some new feature and might not run.
994 .\"O .B exp_version
995 .\"O returns an error if the major numbers match, but the script minor number
996 .\"O is greater than that of the running
997 .\"O .BR Expect .
998 2 番めの番号はマイナー番号である。
999 使っている Expect よりマイナー番号がより大きい Expect 向けのスクリプトは、
1000 新機能の使用未使用によるが、動かないかも知れない。
1001 .B exp_version
1002 はメジャー番号がマッチしてもマイナー番号が使っている
1003 .BR Expect
1004 のバージョンより大きいとエラーを返す。
1005 .IP
1006 .\"O Third is a number that plays no part in the version comparison.
1007 .\"O However, it is incremented when the
1008 .\"O .B Expect
1009 .\"O software
1010 .\"O distribution is changed in any way, such as by additional documentation
1011 .\"O or optimization.  It is reset to 0 upon each new minor version.
1012 3番めの番号は、バージョン比較には使われない。
1013 しかし、文書の更新やプログラムの最適化が行なわれて、
1014 .B Expect
1015 のディストリビューションが更新されると、番号が増えていく。
1016 新しいマイナーバージョンが設定される度に、0 にリセットされる。
1017 .IP
1018 .\"O With the
1019 .\"O .B \-exit
1020 .\"O flag,
1021 .\"O .B Expect
1022 .\"O prints an error and exits if the version is out of date.
1023 .B \-exit
1024 フラグをつけると、バージョンが合わなかった時に
1025 .B Expect
1026 はエラーを表示し exit する。
1027 .TP
1028 .BI expect " [[\-opts] pat1 body1] ... [\-opts] patn [bodyn]"
1029 .\"O waits until one of the patterns matches the output of a spawned process,
1030 .\"O a specified time period has passed, or an end-of-file is seen.
1031 .\"O If the final body is empty, it may be omitted.
1032 .\"O .IP
1033 .\"O Patterns from the most recent
1034 .\"O .B expect_before
1035 .\"O command are implicitly used before any other patterns.
1036 .\"O Patterns from the most recent
1037 .\"O .B expect_after
1038 .\"O command are implicitly used after any other patterns.
1039 は、spawn されたプロセスの出力がパターンのどれかにマッチするか、
1040 指定された時間が経過するか、enf-of-file を見つけるか、のいずれかが
1041 成立するまでウェイトする。
1042 最後の body が空なら、それは省略できる。
1043 .IP
1044 一番最後に実行された
1045 .B expect_before
1046 コマンドのパターンが、どのパターンより先にチェックされる。
1047 一番最後に実行された
1048 .B expect_after
1049 コマンドのパターンが、どのパターンより後にチェックされる。
1050 .IP
1051 .\"O If the arguments to the entire
1052 .\"O .B expect
1053 .\"O statement require more than one line,
1054 .\"O all the arguments may be "braced" into one so as to avoid terminating each
1055 .\"O line with a backslash.  In this one case, the usual Tcl substitutions will
1056 .\"O occur despite the braces.
1057 .B expect
1058 全体への引数が 1 行に収まらなかった場合は、
1059 引数を"ブレース"することで、各行の終りにバックスラッシュをつけるのを
1060 避けることができる。この場合、ブレースしたにもかかわらず通常の Tcl 展開が
1061 発生する。
1062 .IP
1063 .\"O If a pattern is the keyword
1064 .\"O .BR eof ,
1065 .\"O the corresponding body is executed upon end-of-file.
1066 .\"O If a pattern is the keyword
1067 .\"O .BR timeout ,
1068 .\"O the corresponding body is executed upon timeout.  If no timeout keyword
1069 .\"O is used, an implicit null action is executed upon timeout.
1070 .\"O The default timeout period is 10 seconds but may be set, for example to 30,
1071 .\"O by the command "set timeout 30".  An infinite timeout may be designated
1072 .\"O by the value \-1.
1073 .\"O If a pattern is the keyword
1074 .\"O .BR default ,
1075 .\"O the corresponding body is executed upon either timeout or end-of-file.
1076 もし、パターンがキーワード
1077 .BR eof
1078 であれば、end-of-file 発見時に処理が実行される。
1079 もし、パターンがキーワード
1080 .BR timeout
1081 であれば、タイムアウトが発生した時に処理が実行される。
1082 timeout キーワードが使われなかった場合、タイムアウト時にはなにもしない。
1083 デフォルトタイムアウトは 10 秒である。設定することもできる。
1084 例えば 30 秒と設定したければ、"set timeout 30"を実行すること。
1085 タイムアウトさせないためには、値 \-1 を設定する。
1086 もし、パターンがキーワード
1087 .BR default
1088 であれば、タイムアウトか end-of-file のいずれかで処理が実行される。
1089 .IP
1090 .\"O If a pattern matches, then the corresponding body is executed.
1091 .\"O .B expect
1092 .\"O returns the result of the body (or the empty string if no pattern matched).
1093 .\"O In the event that multiple patterns match, the one appearing first is
1094 .\"O used to select a body.
1095 パターンにマッチすれば、処理は実行される。
1096 .B expect
1097 は、行なった処理(関連するブレース内の処理)の結果を返す。
1098 (パターンにマッチしなかった時は、空文字列を返す。)
1099 複数のパターンにマッチした場合、最初にマッチしたパターンに対応する処理が
1100 実行される。
1101 .IP
1102 .\"O Each time new output arrives, it is compared to each pattern in the order
1103 .\"O they are listed.  Thus, you may test for absence of a match by making
1104 .\"O the last pattern something guaranteed to appear, such as a prompt.
1105 .\"O In situations where there is no prompt, you must use
1106 .\"O .B timeout
1107 .\"O (just like you would if you were interacting manually).
1108 対話型プログラムからの新しい出力が Expect に届くたびに、リストされている順に
1109 パターンとの比較が行なわれる。それゆえ、マッチすべきものがないことを
1110 確認するために、プロンプトのように来ることがわかっているパターンを用意する
1111 ことができる。
1112 プロンプトがない場合には、(あなたが手で打つ時に判断しているように)
1113 .B timeout
1114 を用いなければならない。
1115 .IP
1116 .\"O Patterns are specified in three ways.  By default, 
1117 .\"O patterns are specified as with Tcl's
1118 .\"O .B string match
1119 .\"O command.  (Such patterns are also similar to C-shell regular expressions
1120 .\"O usually referred to as "glob" patterns).  The
1121 .\"O .B \-gl
1122 .\"O flag may may
1123 .\"O be used to protect patterns that might otherwise match
1124 .\"O .B expect
1125 .\"O flags from doing so.
1126 .\"O Any pattern beginning with a "-" should be protected this way.  (All strings
1127 .\"O starting with "-" are reserved for future options.)
1128 パターンは 3 通りに書ける。デフォルトは、Tcl の
1129 .B string match
1130 コマンドの書式である。(このパターンはグロブで参照される C-shell の正規表現に
1131 似ている。)
1132 .B \-gl
1133 フラグは、他のマッチからパターンを保護するのに使う。
1134 "-"で始まるパターンは、この方法で保護すべきである。
1135 ("-"で始まる文字列は将来の拡張で、オプションとして使われるかも知れないから)
1136
1137
1138 .IP
1139 .\"O For example, the following fragment looks for a successful login.
1140 .\"O (Note that
1141 .\"O .B abort
1142 .\"O is presumed to be a procedure defined elsewhere in the script.)
1143 例えば、以下の断片はログインの成功を監視する。
1144 .RB ( abort
1145 はスクリプトのどこか他の場所で定義されていると仮定している。
1146 注意すること。)
1147 .nf
1148
1149 .ta \w'      expect 'u +\w'invalid password    'u
1150     expect {
1151         busy               {puts busy\\n ; exp_continue}
1152         failed             abort
1153         "invalid password" abort
1154         timeout            abort
1155         connected
1156     }
1157
1158 .fi
1159 .\"O Quotes are necessary on the fourth pattern since it contains a space, which
1160 .\"O would otherwise separate the pattern from the action.
1161 .\"O Patterns with the same action (such as the 3rd and 4th) require listing the
1162 .\"O actions again.  This can be avoid by using regexp-style patterns (see below).
1163 .\"O More information on forming glob-style patterns can be found in the Tcl manual.
1164 4番めのパターンにはスペースが含まれているのでクオートが必要である。
1165 アクションとパターンを分離するセパレータでないことを指示する必要がある。
1166 (3番めと4番めの)ように同じアクションを持つリクエストも並べて書く必要が
1167 ある。これは、正規表現パターンを用いることで回避できる(下記参照)。
1168 グロブスタイルパターンについてもっと情報が欲しければ、Tcl のマニュアルを
1169 読むこと。
1170 .IP
1171 .\"O Regexp-style patterns follow the syntax defined by Tcl's
1172 .\"O .B regexp
1173 .\"O (short for "regular expression") command.
1174 .\"O regexp patterns are introduced with the flag
1175 .\"O .BR \-re .
1176 .\"O The previous example can be rewritten using a regexp as:
1177 正規表現パターンは、Tcl の
1178 .B regexp
1179 ("regular expression"の短縮)コマンドで定義される文法に従う。
1180 regexpパターンは、
1181 .BR \-re
1182 フラグで始める。
1183 前の例を、regexp で書き直すと、こうなる。:
1184 .nf
1185
1186 .ta \w'      expect 'u +\w'connected    'u
1187     expect {
1188         busy       {puts busy\\n ; exp_continue}
1189         \-re "failed|invalid password" abort
1190         timeout    abort
1191         connected
1192     }
1193
1194 .fi
1195 .\"O Both types of patterns are "unanchored".  This means that patterns
1196 .\"O do not have to match the entire string, but can begin and end the
1197 .\"O match anywhere in the string (as long as everything else matches).
1198 .\"O Use ^ to match the beginning of a string, and $ to match the end.
1199 .\"O Note that if you do not wait for the end of a string, your responses
1200 .\"O can easily end up in the middle of the string as they are echoed from
1201 .\"O the spawned process.  While still producing correct results, the output
1202 .\"O can look unnatural.  Thus, use of $ is encouraged if you can exactly
1203 .\"O describe the characters at the end of a string.
1204 .\"O 
1205 .\"O Note that in many editors, the ^ and $ match the beginning and end of
1206 .\"O lines respectively. However, because expect is not line oriented,
1207 .\"O these characters match the beginning and end of the data (as opposed
1208 .\"O to lines) currently in the expect matching buffer.  (Also, see the
1209 .\"O note below on "system indigestion.")
1210 .\"O 
1211 .\"O The
1212 .\"O .B \-ex
1213 .\"O flag causes the pattern to be matched as an "exact" string.  No
1214 .\"O interpretation of *, ^, etc is made (although the usual Tcl
1215 .\"O conventions must still be observed).
1216 .\"O Exact patterns are always unanchored.
1217 どちらのパターンのタイプも、"固定されていない"。どういう意味かというと、
1218 文字列全体にマッチする必要はなくて、文字列のどこでもマッチすれば
1219 良いということである。^ が先頭にマッチする。 $ が末尾にマッチする。
1220 文字列の末尾にマッチさせなければ、spawn されたプロセスからエコーされた
1221 文字列の途中で切り上げてレスポンスを返せることに注意すること。
1222 正しく処理が実行されていても、出力は不自然に見える可能性がある。
1223 それで、文字列の終りの文字を正確に記述できるなら、$ を使うことを勧める。
1224
1225 多くのエディタでは、^ と $ は行頭、行末に正確にマッチする。
1226 しかし、expect は行指向ではないので、(行ではなく)データの始まりと終りに
1227 マッチする。
1228 ("EXPECTヒント"内の、バッファリングの消化不良に関する部分を参照のこと)
1229
1230 .B \-ex
1231 フラグは、"正確に(exact)"指示された文字列にマッチする。
1232 * や ^ などの解釈は行なわれない。(ただし、通常の Tcl 展開は行なわれる)。
1233 Exact パターンは常に固定されている。
1234
1235
1236 .IP
1237 .\"O The
1238 .\"O .B \-nocase
1239 .\"O flag causes uppercase characters of the output to compare as if they were
1240 .\"O lowercase characters.  The pattern is not affected.
1241 .B \-nocase
1242 フラグは、小文字が含まれている場合に大文字に変換してからマッチさせる。
1243 パターンには影響しない。
1244 .IP
1245 .\"O While reading output,
1246 .\"O more than 2000 bytes can force earlier bytes to be "forgotten".
1247 .\"O This may be changed with the function
1248 .\"O .BR match_max .
1249 .\"O (Note that excessively large values can slow down the pattern matcher.)
1250 .\"O If
1251 .\"O .I patlist
1252 .\"O is
1253 .\"O .BR full_buffer ,
1254 .\"O the corresponding body is executed if
1255 .\"O .I match_max
1256 .\"O bytes have been received and no other patterns have matched.
1257 .\"O Whether or not the
1258 .\"O .B full_buffer
1259 .\"O keyword is used, the forgotten characters are written to
1260 .\"O expect_out(buffer).
1261 出力を読んでいて、2000 バイトを超えてしまったデータは"忘れられる"。
1262 この動作は、
1263 .BR match_max
1264 関数で変更できる。
1265 (極端に大きな値はパターンマッチの性能を低下させることに注意すること。)
1266 .I patlist
1267
1268 .BR full_buffer
1269 を指定すると、
1270 .I match_max
1271 バイト以上のデータを受けてパターンマッチしなかったときに、処理が実行される。
1272 .B full_buffer
1273 キーワードの有無に関わらず、忘れられたデータは
1274 expect_out(buffer)
1275 に保存される。
1276
1277 .\"O If
1278 .\"O .I patlist
1279 .\"O is the keyword
1280 .\"O .BR null ,
1281 .\"O and nulls are allowed (via the
1282 .\"O .B remove_nulls
1283 .\"O command), the corresponding body is executed if a single ASCII
1284 .\"O 0 is matched.
1285 .\"O It is not possible to
1286 .\"O match 0 bytes via glob or regexp patterns.
1287 .I patlist
1288 に、キーワード
1289 .BR null
1290 を指定すると、ヌル文字が許可され
1291 (
1292 .B remove_nulls
1293 コマンドを通して)、ヌル文字(ASCII 0)にマッチする。
1294 glob や regexp では 0 バイトにマッチすることができない。
1295
1296 .\"O Upon matching a pattern (or eof or full_buffer),
1297 .\"O any matching and previously unmatched output is saved in the variable
1298 .\"O .IR expect_out(buffer) .
1299 .\"O Up to 9 regexp substring matches are saved in the variables
1300 .\"O .I expect_out(1,string)
1301 .\"O through
1302 .\"O .IR expect_out(9,string) .
1303 .\"O If the
1304 .\"O .B -indices
1305 .\"O flag is used before a pattern,
1306 .\"O the starting and ending indices (in a form suitable for
1307 .\"O .BR lrange )
1308 .\"O of the
1309 .\"O 10 strings are stored in the variables
1310 .\"O .I expect_out(X,start)
1311 .\"O and
1312 .\"O .I expect_out(X,end)
1313 .\"O where X is a digit, corresponds to the substring position in the buffer.
1314 .\"O 0 refers to strings which matched the entire pattern
1315 .\"O and is generated for glob patterns as well as regexp patterns.
1316 パターン(あるいは、eol, full_buffer)にマッチすると、マッチした部分の文字列か、
1317 その前のマッチしなかった文字列が、変数
1318 .IR expect_out(buffer)
1319 に保存される。
1320
1321 9 個までのマッチした部分文字列は、変数
1322 .I expect_out(1,string)
1323 から
1324 .IR expect_out(9,string)
1325 に保存される。
1326 .B -indices
1327 フラグをパターンの前で指定すると、マッチした部分文字列の
1328 開始位置と終了位置が(
1329 .BR lrange
1330 の引数として使える形で)、変数
1331 .I expect_out(X,start)
1332
1333 .I expect_out(X,end)
1334 に保存される。
1335 X は数字で 0 〜 9 まで。
1336 0 はパターン全体がマッチした部分を指示する。
1337 .\"O For example, if a process has produced output of "abcdefgh\\n", the result of:
1338 例えば、プロセスが"abcdefgh\\n"を出力し、以下の形:
1339 .nf
1340
1341     expect "cd"
1342
1343 .fi
1344 .\"O is as if the following statements had executed:
1345 で受けると、以下の文を実行したのと同じ結果となる。
1346 .nf
1347
1348     set expect_out(0,string) cd
1349     set expect_out(buffer) abcd
1350
1351 .fi
1352 .\"O and "efgh\\n" is left in the output buffer.
1353 この時、"efgh\\n"は出力バッファに残る。
1354 .\"O If a process produced the output "abbbcabkkkka\\n", the result of:
1355 プロセスが"abbbcabkkkka\\n"を出力し、以下の形:
1356 .nf
1357
1358     expect \-indices \-re "b(b*).*(k+)"
1359
1360 .fi
1361 .\"O is as if the following statements had executed:
1362 で受けると、以下の文を実行したのと同じ結果になる。
1363 .nf
1364
1365     set expect_out(0,start) 1
1366     set expect_out(0,end) 10
1367     set expect_out(0,string) bbbcabkkkk
1368     set expect_out(1,start) 2
1369     set expect_out(1,end) 3
1370     set expect_out(1,string) bb
1371     set expect_out(2,start) 10
1372     set expect_out(2,end) 10
1373     set expect_out(2,string) k
1374     set expect_out(buffer) abbbcabkkkk
1375
1376 .fi
1377 .\"O and "a\\n" is left in the output buffer.  The pattern "*" (and -re ".*") will
1378 .\"O flush the output buffer without reading any more output from the
1379 .\"O process.
1380 この時、"a\\n"は出力バッファに残る。
1381 パターン"*" (と -re ".*")は、プロセスからのデータがさらに来ない限り、
1382 出力バッファをフラッシュしない。
1383 .IP
1384 .\"O Normally, the matched output is discarded from Expect's internal buffers.
1385 .\"O This may be prevented by prefixing a pattern with the
1386 .\"O .B \-notransfer
1387 .\"O flag.  This flag is especially useful in experimenting (and can be
1388 .\"O abbreviated to "-not" for convenience while experimenting).
1389 通常、マッチした出力は Expect の内部バッファから、切り捨てらる。
1390 この動作は、
1391 .B \-notransfer
1392 フラグで抑止することができる。このフラグは、スクリプトを試している時に
1393 役に立つ(そして、"-not"と略記しても良い)。
1394
1395 .\"O The spawn id associated with the matching output (or eof or
1396 .\"O full_buffer) is stored in
1397 .\"O .IR expect_out(spawn_id) .
1398 .\"O 
1399 .\"O The
1400 .\"O .B \-timeout
1401 .\"O flag causes the current expect command to use the following value
1402 .\"O as a timeout instead of using the value of the timeout variable.
1403 .\"O 
1404 .\"O By default, 
1405 .\"O patterns are matched against output from the current process, however the
1406 .\"O .B \-i
1407 .\"O flag declares the output from the named spawn_id list be matched against
1408 .\"O any following patterns (up to the next
1409 .\"O .BR \-i ).
1410 .\"O The spawn_id list should either be a whitespace separated list of spawn_ids
1411 .\"O or a variable referring to such a list of spawn_ids.
1412 マッチした出力を送ってきたプロセスへの spawn id は、
1413 .IR expect_out(spawn_id)
1414 に保存される。
1415
1416 .B \-timeout
1417 フラグは、この expect コマンドの中の timeout 時刻を timeout 変数でなく
1418 指示された値に設定する。
1419
1420 デフォルトでは、パターンはカレントプロセスからの出力にマッチさせるのだが、
1421 .B \-i
1422 フラグを設定すると、指定された spawn_id リストに対応するプロセス群からの出力に
1423 マッチさせることができる。(次の
1424 .BR \-i
1425 での指定があるまで有効である。)
1426 spawn_id リストは、スペースで区切った spawn_id のリストか、そのような値を持つ
1427 変数への参照でなくてはならない。
1428
1429 .\"O For example, the following example waits for
1430 .\"O "connected" from the current process, or "busy", "failed" or "invalid
1431 .\"O password" from the spawn_id named by $proc2.
1432 例えば、以下の例はカレントプロセスからの"connected"と
1433 $proc2 と言う名前の spawn_id からの"busy","failed","invalid password"
1434 を待ち受ける。
1435 .nf
1436
1437     expect {
1438         \-i $proc2 busy {puts busy\\n ; exp_continue}
1439         \-re "failed|invalid password" abort
1440         timeout abort
1441         connected
1442     }
1443
1444 .fi
1445 .\"O The value of the global variable
1446 .\"O .I any_spawn_id
1447 .\"O may be used to match patterns to any spawn_ids that are named
1448 .\"O with all other
1449 .\"O .B \-i
1450 .\"O flags in the current
1451 .\"O .B expect
1452 .\"O command.
1453 .\"O The spawn_id from a
1454 .\"O .B \-i
1455 .\"O flag with no associated pattern (i.e., followed immediately
1456 .\"O by another
1457 .\"O .BR \-i )
1458 .\"O is made available to any other patterns
1459 .\"O in the same
1460 .\"O .B expect
1461 .\"O command associated with
1462 .\"O .I any_spawn_id.
1463 .\"O 
1464 .\"O The
1465 .\"O .B \-i
1466 .\"O flag may also name a global variable in which case the variable is read
1467 .\"O for a list of spawn ids.  The variable is reread whenever it changes.
1468 .\"O This provides a way of changing the I/O source while the command is in
1469 .\"O execution.  Spawn ids provided this way are called "indirect" spawn ids.
1470 .\"O 
1471 .\"O Actions such as
1472 .\"O .B break
1473 .\"O and
1474 .\"O .B continue
1475 .\"O cause control structures (i.e.,
1476 .\"O .BR for ,
1477 .\"O .BR proc )
1478 .\"O to behave in the usual way.
1479 .\"O The command
1480 .\"O .B exp_continue
1481 .\"O allows
1482 .\"O .B expect
1483 .\"O itself to continue
1484 .\"O executing rather than returning as it normally would.
1485 大域変数
1486 .I any_spawn_id
1487 の値は、
1488 今の
1489 .B expect
1490 コマンド内で
1491 .B \-i
1492 フラグを指示した spawn_id の全てにマッチさせるために使われる。
1493 .B \-i
1494 フラグをパターンなしで指定すると(すなわち、別の
1495 .BR \-i
1496 が直後に続くと)、
1497 .I any_spawn_id
1498 で指定された、同じ
1499 .B expect
1500 コマンド内の他のパターンに対して、有効になる。
1501
1502 .B \-i
1503 フラグには、グローバル変数の名前を指定することもできる。その場合、
1504 その変数は、spawn id のリストである。変数は変わるたびに読み直される。
1505 こうすることで、コマンドが実行されている間に I/O ソースを変更すること
1506 ができる。この方法で指定される spawn id を"間接(indirect)" spawn id
1507 と呼ぶ。
1508
1509 .B break
1510
1511 .B continue
1512 などのアクションは、制御構造(すなわち、
1513 .BR for , proc
1514 )内で通常通りの振舞いをする。
1515
1516 .B exp_continue
1517 コマンドは、
1518 .B expect
1519 ループから抜けるような状況で実行を続けさせる。
1520 .IP
1521 .\"O This is useful for avoiding explicit loops or repeated expect statements.
1522 .\"O The following example is part of a fragment to automate rlogin.  The
1523 .\"O .B exp_continue
1524 .\"O avoids having to write a second
1525 .\"O .B expect
1526 .\"O statement (to look for the prompt again) if the rlogin prompts for a password.
1527 ループを書いたり、expect コマンドを繰り返すことを避ける時に便利である。
1528 以下の例はログインを自動化するコードの断片である。
1529 .B exp_continue
1530 によって、(再びプロンプトを探すための)2 つめの
1531 .B expect
1532 コマンドを書かなくて済んでいる。
1533 .nf
1534
1535     expect {
1536         Password: {
1537             stty -echo
1538             send_user "password (for $user) on $host: "
1539             expect_user -re "(.*)\\n"
1540             send_user "\\n"
1541             send "$expect_out(1,string)\\r"
1542             stty echo
1543             exp_continue
1544         } incorrect {
1545             send_user "invalid password or account\\n"
1546             exit
1547         } timeout {
1548             send_user "connection to $host timed out\\n"
1549             exit
1550         } eof {
1551             send_user \\
1552                 "connection to host failed: $expect_out(buffer)"
1553             exit
1554         } -re $prompt
1555     }
1556
1557 .fi
1558 .\"O For example, the following fragment might help a user guide
1559 .\"O an interaction that is already totally automated.  In this case, the terminal
1560 .\"O is put into raw mode.  If the user presses "+", a variable is incremented.
1561 .\"O If "p" is pressed, several returns are sent to the process,
1562 .\"O perhaps to poke it in some way, and "i" lets the user interact with the
1563 .\"O process, effectively stealing away control from the script.
1564 .\"O In each case, the
1565 .\"O .B exp_continue
1566 .\"O allows the current
1567 .\"O .B expect
1568 .\"O to continue pattern matching after executing the
1569 .\"O current action.
1570 例えば、以下の断片は既に自動化されているユーザーガイドへのやりとりを
1571 補助する。
1572 この場合、端末は raw モードになる。
1573 ユーザーが'+'を押すと変数がインクリメントされる。
1574 "p"が押されると、プロセスへ復帰情報が送られる。
1575 おそらくは同じように"i"が押されると、スクリプトから制御を奪い、
1576 ユーザーからの制御が行なえる。
1577 どの場合も
1578 .B exp_continue
1579 コマンドが、今の
1580 .B expect
1581 に、処理を行なわせた後再びパターンマッチさせている。
1582 .nf
1583
1584     stty raw \-echo
1585     expect_after {
1586         \-i $user_spawn_id
1587         "p" {send "\\r\\r\\r"; exp_continue}
1588         "+" {incr foo; exp_continue}
1589         "i" {interact; exp_continue}
1590         "quit" exit
1591     }
1592
1593 .fi
1594 .IP
1595 .\"O By default,
1596 .\"O .B exp_continue
1597 .\"O resets the timeout timer.  The timer is not restarted, if
1598 .\"O .B exp_continue
1599 .\"O is called with the 
1600 .\"O .B \-continue_timer
1601 .\"O flag.
1602 デフォルトでは、
1603 .B exp_continue
1604 は、タイムアウトタイマーをリセットする。
1605 タイマを再開させるには、
1606 .B exp_continue
1607 コマンドに
1608 .B \-continue_timer
1609 フラグをつける。
1610 .TP
1611 .BI expect_after " [expect_args]"
1612 .\"O works identically to the
1613 .\"O .B expect_before
1614 .\"O except that if patterns from both
1615 .\"O .B expect
1616 .\"O and
1617 .\"O .B expect_after
1618 .\"O can match, the
1619 .\"O .B expect
1620 .\"O pattern is used.  See the
1621 .\"O .B expect_before
1622 .\"O command for more information.
1623 は、
1624 .B expect_before
1625 と同様の動きをするが、
1626 .B expect
1627
1628 .B expect_after
1629 の両方にマッチした場合、
1630 .B expect
1631 のパターンが使用される点が異なる。
1632 より詳しい情報は、
1633 .B expect_before
1634 コマンドの項を参照のこと。
1635 .TP
1636 .BI expect_background " [expect_args]"
1637 .\"O takes the same arguments as
1638 .\"O .BR expect ,
1639 .\"O however it returns immediately.
1640 .\"O Patterns are tested whenever new input arrives.
1641 .\"O The pattern
1642 .\"O .B timeout
1643 .\"O and
1644 .\"O .B default
1645 .\"O are meaningless to
1646 .\"O .BR expect_background
1647 .\"O and are silently discarded.
1648 .\"O Otherwise, the
1649 .\"O .B expect_background
1650 .\"O command uses
1651 .\"O .B expect_before
1652 .\"O and
1653 .\"O .B expect_after
1654 .\"O patterns just like
1655 .\"O .B expect
1656 .\"O does.
1657 .\"O 
1658 .\"O When
1659 .\"O .B expect_background
1660 .\"O actions are being evaluated, background processing for the same
1661 .\"O spawn id is blocked.  Background processing is unblocked when
1662 .\"O the action completes.  While background processing is blocked,
1663 .\"O it is possible to do a (foreground)
1664 .\"O .B expect
1665 .\"O on the same spawn id.
1666 .\"O 
1667 .\"O It is not possible to execute an
1668 .\"O .B expect
1669 .\"O while an
1670 .\"O .B expect_background
1671 .\"O is unblocked.
1672 .\"O .B expect_background
1673 .\"O for a particular spawn id is deleted by
1674 .\"O declaring a new expect_background with the same spawn id.  Declaring
1675 .\"O .B expect_background
1676 .\"O with no pattern removes the given spawn id
1677 .\"O from the ability to match patterns in the background.
1678 は、
1679 .BR expect
1680 と同じ引数をとるが、その場で復帰する。
1681 パターンは新しいデータが届くたびにチェックされる。
1682 パターン
1683 .B timeout
1684
1685 .B default
1686 は、
1687 .BR expect_background
1688 には、意味がないし、無視される。
1689 .B expect
1690 と同様に、
1691 .B expect_background
1692 コマンドは
1693 .B expect_before
1694
1695 .B expect_after
1696 パターンを使える。
1697
1698 .B expect_background
1699 アクションが、評価される時、同じ spawn id を持つ
1700 バックグラウンドプロセスはブロックされる。
1701 アクションが完了すると、プロセスがアンブロックされる。
1702 バックグラウンドプロセスがブロックされている間は、
1703 (フォアグラウンドの)
1704 .B expect
1705 で、同じ spawn id に接続することができる。
1706 逆に、
1707 .B expect_background
1708 がブロックされていない間は
1709 .B expect
1710 することができない。
1711 特定の spawn id への
1712 .B expect_background
1713 は、同一 spawn id への新しい expect_background を指定すると
1714 削除される。
1715 パターンをつけない
1716 .B expect_background
1717 を指定することで、バックグラウンドでパターンマッチさせること
1718 をやめさせられる。
1719 .TP
1720 .BI expect_before " [expect_args]"
1721 .\"O takes the same arguments as
1722 .\"O .BR expect ,
1723 .\"O however it returns immediately.
1724 .\"O Pattern-action pairs from the most recent
1725 .\"O .B expect_before
1726 .\"O with the same spawn id are implicitly added to any following
1727 .\"O .B expect
1728 .\"O commands.  If a pattern matches, it is treated as if it had been
1729 .\"O specified in the
1730 .\"O .B expect
1731 .\"O command itself, and the associated body is executed in the context
1732 .\"O of the
1733 .\"O .B expect
1734 .\"O command.
1735 .\"O If patterns from both
1736 .\"O .B expect_before
1737 .\"O and
1738 .\"O .B expect
1739 .\"O can match, the
1740 .\"O .B expect_before
1741 .\"O pattern is used.
1742 .\"O 
1743 .\"O If no pattern is specified, the spawn id is not checked for any patterns.
1744 .\"O 
1745 .\"O Unless overridden by a
1746 .\"O .B \-i
1747 .\"O flag,
1748 .\"O .B expect_before
1749 .\"O patterns match against the spawn id defined at the time that the 
1750 .\"O .B expect_before
1751 .\"O command was executed (not when its pattern is matched).
1752
1753 .BR expect
1754 と同じ引数をとるが、その場で復帰する。
1755 もっとも最近、同じ spawn id に対して
1756 .B expect_before
1757 で使われたパターン・アクションのペアが、続く
1758 .B expect
1759 コマンドに対して使用される。
1760 パターンがマッチすると、
1761 .B expect
1762 コマンドにマッチした時と同じように動作する。
1763 処理は、その
1764 .B expect
1765 のコンテキストで行なわれる。
1766 .B expect_before
1767
1768 .B expect
1769 の両方のパターンにマッチした場合、
1770 .B expect_before
1771 のパターンが使われる。
1772
1773 パターンが指示されなかった場合、spawn id は
1774 どのパターンでもチェックされない。
1775
1776 .B \-i
1777 フラグをさらに指定しない限り、
1778 .B expect_before
1779 パターンは、
1780 .B expect_before
1781 が実行された時に定義されたパターンにマッチする。
1782
1783 .\"O The \-info flag causes
1784 .\"O .B expect_before
1785 .\"O to return the current specifications of what patterns it will match.
1786 .\"O By default, it reports on the current spawn id.  An optional spawn id specification may be given for information on that spawn id.  For example
1787 \-info フラグは
1788 .B expect_before
1789 から、マッチパターンの現在の状態を復帰させる。
1790 デフォルトでは、現在の spawn id に報告する。オプションの spawn id を
1791 指定することもできる。例えば、
1792 .nf
1793
1794     expect_before -info -i $proc
1795
1796 .fi
1797 .\"O At most one spawn id specification may be given.  The flag \-indirect
1798 .\"O suppresses direct spawn ids that come only from indirect specifications.
1799 .\"O 
1800 .\"O Instead of a spawn id specification, the flag "-all" will cause
1801 .\"O "-info" to report on all spawn ids.
1802 .\"O 
1803 .\"O The output of the \-info flag can be reused as the argument to expect_before.
1804 たった一つの spawn id 指定だけが許される。\-indirect フラグで、直接
1805 spawn id を抑止し、間接的な指定から得られるidを指示する。
1806
1807 spawn id を指示する代わりに、"-all"フラグを使って、
1808 全ての spawn id に "-info" の報告をさせることができる。
1809
1810 \-info フラグを使った時の出力結果は、expect_before への引数として
1811 再利用できる。
1812 .TP
1813 .BI expect_tty " [expect_args]"
1814 .\"O is like
1815 .\"O .B expect
1816 .\"O but it reads characters from /dev/tty (i.e. keystrokes from the user).
1817 .\"O By default, reading is performed in cooked mode.
1818 .\"O Thus, lines must end with a return in order for
1819 .\"O .B expect
1820 .\"O to see them.
1821 .\"O This may be changed via
1822 .\"O .B stty
1823 .\"O (see the
1824 .\"O .B stty
1825 .\"O command below).
1826 は、
1827 .B expect
1828 と似た動きをするが、文字列を /dev/tty (すなわち、ユーザーからのキー入力)
1829 から読み込む。
1830 デフォルトでは、cooked mode で読み込まれるので、
1831 行はリターンで終らなければならない。そうしないと
1832 .B expect
1833 が読めない。この動きは、
1834 .B stty
1835 を使って変えられる。
1836 (下の
1837 .B stty
1838 コマンドを参照)
1839 .TP
1840 .BI expect_user " [expect_args]"
1841 .\"O is like
1842 .\"O .B expect
1843 .\"O but it reads characters from stdin (i.e. keystrokes from the user).
1844 .\"O By default, reading is performed in cooked mode.
1845 .\"O Thus, lines must end with a return in order for
1846 .\"O .B expect
1847 .\"O to see them.
1848 .\"O This may be changed via
1849 .\"O .B stty
1850 .\"O (see the
1851 .\"O .B stty
1852 .\"O command below).
1853
1854 .B expect
1855 と似た動きをするが、文字列を stdin(すなわち、ユーザーからのキー入力)
1856 から読み込む。
1857 デフォルトでは、cooked mode で読み込まれるので、
1858 行はリターンで終らなければならない。そうしないと
1859 .B expect
1860 が読めない。この動きは、
1861 .B stty
1862 を使って変えられる。
1863 (下の
1864 .B stty
1865 コマンドを参照)
1866 .TP
1867 .B fork
1868 .\"O creates a new process.  The new process is an exact copy of the current
1869 .\"O .B Expect
1870 .\"O process.  On success,
1871 .\"O .B fork
1872 .\"O returns 0 to the new (child) process and returns the process ID of the child
1873 .\"O process to the parent process.
1874 .\"O On failure (invariably due to lack of resources, e.g., swap space, memory),
1875 .\"O .B fork
1876 .\"O returns \-1 to the parent process, and no child process is created.
1877 は、新しいプロセスを作る。この新しいプロセスは、現在の
1878 .B Expect
1879 プロセスの正確なコピーである。
1880 成功すると
1881 .B fork
1882 は 新しい(子)プロセスに 0 を返し、親プロセスに 子プロセスのプロセスIDを
1883 返す。
1884 失敗する(スワップ、メモリなどのリソース不足か?)と、
1885 .B fork
1886 は、親プロセスに \-1 を返す。新しい子プロセスは作成されない。
1887 .\"O .IP
1888 .\"O Forked processes exit via the
1889 .\"O .B exit
1890 .\"O command, just like the original process.
1891 .\"O Forked processes are allowed to write to the log files.  If you do not
1892 .\"O disable debugging or logging in most of the processes, the result can be
1893 .\"O confusing.
1894 .IP
1895 フォークされたプロセスは、
1896 .B exit
1897 コマンドで ext できる。元のプロセスと同様である。
1898 フォークされたプロセスはログファイルを作っても良い。多くのプロセスで
1899 デバッグもログもできなければ、結果、混乱するだけである。
1900 .\"O .IP
1901 .\"O Some pty implementations may be confused by multiple readers and writers,
1902 .\"O even momentarily.  Thus, it is safest to
1903 .\"O .B fork
1904 .\"O before spawning processes.
1905 .IP
1906 pty のインプリメンテーションの中には、複数の読み手と書き手が一瞬でもあれば、
1907 混乱するものがある。それで、プロセスを spawn する前には
1908 .B fork
1909 しておくのが一番安全である。
1910 .TP
1911 .BI interact " [string1 body1] ... [stringn [bodyn]]"
1912 .\"O gives control of the current process to the user, so that
1913 .\"O keystrokes are sent to the current process,
1914 .\"O and the stdout and stderr of the current process are returned.
1915 は、現プロセスの制御をユーザーに渡す。結果、
1916 現プロセスに送られたキーストロークと現プロセスの標準出力と標準エラー出力が
1917 復帰する。
1918 .IP
1919 .\"O String-body pairs may be specified as arguments, in which case the
1920 .\"O body is executed when the corresponding string is entered.  (By default, the
1921 .\"O string is not sent to the current process.)   The
1922 .\"O .B interpreter
1923 .\"O command is assumed, if the final body is missing.
1924 string と body の組が、引数として指示できる。(デフォルトでは、
1925 文字列は現プロセスには送られない)
1926 最後の body がないと、
1927 .B interpreter
1928 コマンドが実行される。
1929 .IP
1930 .\"O If the arguments to the entire
1931 .\"O .B interact
1932 .\"O statement require more than one line,
1933 .\"O all the arguments may be "braced" into one so as to avoid terminating each
1934 .\"O line with a backslash.  In this one case, the usual Tcl substitutions will
1935 .\"O occur despite the braces.
1936 .B interact
1937 コマンド全体への引数が一行に収まらない場合、"brace"することで各行の終りに
1938 バックスラッシュを入れるのを避けることができる。この場合、Tcl の展開は
1939 ブレースしてあっても起こる。
1940 .IP
1941 .\"O For example, the following command runs interact with the following
1942 .\"O string-body pairs defined:  When ^Z is pressed,
1943 .\"O .B Expect
1944 .\"O is suspended.
1945 .\"O (The
1946 .\"O .B \-reset
1947 .\"O flag restores the terminal modes.)
1948 .\"O When ^A is pressed, the user sees "you typed a control-A" and the
1949 .\"O process is sent a ^A.  When $ is pressed, the user sees the date.
1950 .\"O When ^C is pressed,
1951 .\"O .B Expect
1952 .\"O exits.  If "foo" is entered, the user sees "bar".
1953 .\"O When ~~ is pressed, the
1954 .\"O .B Expect
1955 .\"O interpreter runs interactively.
1956 例えば、以下のコマンドは続く string body の組と対話する。
1957 : ^Z が押されると
1958 .B Expect
1959 はサスペンドする。
1960 (
1961 .B \-reset
1962 フラグは、端末モードを復旧させる。)
1963 ^A が押されると、ユーザーには"you typed a control-A"が返る。
1964  $ が押されると、ユーザーには日付が返る。
1965 ^C が押されると、
1966 .B Expect
1967 は、exit する。
1968 "foo"が入力されると、ユーザーに "bar" が返る。
1969 ~~ が押されると、
1970 .B Expect
1971 インタプリタは、対話モードになる。
1972 .nf
1973
1974 .ta \w'    interact 'u +\w'$CTRLZ  'u +\w'{'u
1975     set CTRLZ \\032
1976     interact {
1977         -reset $CTRLZ {exec kill \-STOP [pid]}
1978         \\001   {send_user "you typed a control\-A\\n";
1979                 send "\\001"
1980                }
1981         $      {send_user "The date is [exec date]."}
1982         \\003   exit
1983         foo    {send_user "bar"}
1984         ~~
1985     }
1986
1987 .fi
1988 .IP
1989 .\"O In string-body pairs, strings are matched in the order they are listed
1990 .\"O as arguments.  Strings that partially match are not sent to the
1991 .\"O current process in anticipation of the remainder coming.  If
1992 .\"O characters are then entered such that there can no longer possibly be
1993 .\"O a match, only the part of the string will be sent to the process that cannot
1994 .\"O possibly begin another match.  Thus, strings that are substrings of
1995 .\"O partial matches can match later, if the original strings that was attempting
1996 .\"O to be match ultimately fails.
1997 string と body の組で、string が引数として並べられた順に比較される。
1998 部分的にマッチした文字列は、残りが到着するまで送られて来ない。
1999 何文字かさらに打ち込まれて、マッチが可能になると、今のマッチを判断する
2000 ためにだけ使われて他のマッチを始めることはしない。それゆえ、部分的に
2001 マッチしている文字列のマッチが完了するのは遅れることがある。
2002 部分的にはマッチするが最終的にはマッチしない文字列の場合などである。
2003 .IP
2004 .\"O By default, string matching is exact with no wild cards.  (In contrast,
2005 .\"O the
2006 .\"O .B expect
2007 .\"O command uses glob-style patterns by default.)  The
2008 .\"O .B \-ex
2009 .\"O flag may be used to protect patterns that might otherwise match
2010 .\"O .B interact
2011 .\"O flags from doing so.
2012 .\"O Any pattern beginning with a "-" should be protected this way.    (All strings
2013 .\"O starting with "-" are reserved for future options.)
2014 デフォルトでは、ワイルドカードを含まないマッチは、exactとなる。
2015 (
2016 .B expect
2017 コマンドがデフォルトでグロブスタイルのパターンを用いるのとは対照的に。)
2018 .B \-ex
2019 フラグは、パターンをプロテクトするのに使える。
2020 .B interact
2021 フラグがそうするように。
2022 パターンが"-"で始まる場合、この方法で保護できる。
2023 ("-"で始まる文字列は全て将来のオプションとして予約されている。)
2024
2025 .\"O The
2026 .\"O .B \-re
2027 .\"O flag forces the string to be interpreted as a regexp-style pattern.  In this
2028 .\"O case, matching substrings are stored in the variable
2029 .\"O .I interact_out
2030 .\"O similarly to the way
2031 .\"O .B expect
2032 .\"O stores its output in the variable
2033 .\"O .BR expect_out .
2034 .\"O The
2035 .\"O .B \-indices
2036 .\"O flag is similarly supported.
2037 .\"O 
2038 .\"O The pattern
2039 .\"O .B eof
2040 .\"O introduces an action that is 
2041 .\"O executed upon end-of-file.  A separate
2042 .\"O .B eof
2043 .\"O pattern may also follow the
2044 .\"O .B \-output
2045 .\"O flag in which case it is matched if an eof is detected while writing output.
2046 .\"O The default
2047 .\"O .B eof
2048 .\"O action is "return", so that
2049 .\"O .B interact
2050 .\"O simply returns upon any EOF.
2051 .\"O 
2052 .\"O The pattern
2053 .\"O .B timeout
2054 .\"O introduces a timeout (in seconds) and action that is executed
2055 .\"O after no characters have been read for a given time.
2056 .\"O The
2057 .\"O .B timeout
2058 .\"O pattern applies to the most recently specified process.
2059 .\"O There is no default timeout.
2060 .\"O The special variable "timeout" (used by the
2061 .\"O .B expect
2062 .\"O command) has no affect on this timeout.
2063 .B \-re
2064 フラグは、正規表現スタイルのパターンとして文字列を解釈する。
2065 この場合、マッチした部分文字列は
2066 .I interact_out
2067 に保存される。
2068 .B expect
2069 が、その出力を変数
2070 .BR expect_out
2071 に保存するのと似たようなものである。
2072 .B \-indices
2073 フラグも同じようにサポートされる。
2074
2075 パターン
2076 .B eof
2077 は、end-of-file にマッチした場合にアクションを実行する。
2078 複数に分かれた
2079 .B eof
2080 パターンには
2081 .B \-output
2082 フラグが続いても良い。その場合、出力が書かれている間に eof が検出されると
2083 アクションを実行する。
2084 .B eof
2085 のデフォルトアクションは"return"である。
2086 それで、
2087 .B interact
2088 は、EOF を見つけると復帰する。
2089
2090 .B timeout
2091 パターンは、(秒で表現された)タイムアウトにマッチし、アクションを実行する。
2092 .B timeout
2093 パターンは、最後に指示されたプロセスに適用される。タイムアウトには
2094 デフォルトの値はない。(expect内で使われる)特殊な変数"timeout"は、
2095 このタイムアウトと関係しない。
2096
2097 .\"O For example, the following statement could be used to autologout users who have
2098 .\"O not typed anything for an hour but who still get frequent system
2099 .\"O messages:
2100 例えば、以下の記述は一時間以上タイプしなかったユーザーを自動的にログアウト
2101 させる。その前にシステムから頻繁にメッセージを受けとる:
2102 .nf
2103
2104     interact -input $user_spawn_id timeout 3600 return -output \\
2105         $spawn_id 
2106
2107 .fi
2108
2109 .\"O If the pattern is the keyword
2110 .\"O .BR null ,
2111 .\"O and nulls are allowed (via the
2112 .\"O .B remove_nulls
2113 .\"O command), the corresponding body is executed if a single ASCII
2114 .\"O 0 is matched.
2115 .\"O It is not possible to
2116 .\"O match 0 bytes via glob or regexp patterns.
2117 .\"O 
2118 .\"O Prefacing a pattern with the flag
2119 .\"O .B \-iwrite
2120 .\"O causes the variable
2121 .\"O .I interact_out(spawn_id)
2122 .\"O to be set to the spawn_id which matched the pattern
2123 .\"O (or eof).
2124 .\"O 
2125 .\"O Actions such as
2126 .\"O .B break
2127 .\"O and
2128 .\"O .B continue
2129 .\"O cause control structures (i.e.,
2130 .\"O .BR for ,
2131 .\"O .BR proc )
2132 .\"O to behave in the usual way.
2133 .\"O However
2134 .\"O .B return
2135 .\"O causes interact to return to its caller, while
2136 .\"O .B inter_return
2137 .\"O causes
2138 .\"O .B interact
2139 .\"O to cause a return in its caller.  For example, if "proc foo" called
2140 .\"O .B interact
2141 .\"O which then executed the action
2142 .\"O .BR inter_return ,
2143 .\"O .B proc foo
2144 .\"O would return.  (This means that if
2145 .\"O .B interact
2146 .\"O calls
2147 .\"O .B interpreter
2148 .\"O interactively typing
2149 .\"O .B return
2150 .\"O will cause the interact to continue, while
2151 .\"O .B inter_return
2152 .\"O will cause the interact to return to its caller.)
2153 パターン
2154 .BR null
2155 と nulls は、(
2156 .B remove_nulls
2157 コマンドを通して)、アスキーの 0 にマッチした場合にアクションを実行する。
2158 glob や regexp で 0 バイトにマッチさせることはできない。
2159
2160 このパターンの前に
2161 .B \-iwrite
2162 フラグをつけると、
2163 変数
2164 .I interact_out(spawn_id)
2165 にパターン(あるいはeof)にマッチした spawn_id が設定される。
2166
2167 .B break
2168
2169 .B continue
2170 といったアクションは、制御構造
2171 (すなわち、
2172 .BR for
2173
2174 .BR proc
2175 )の中で、通常通りに動く。
2176 しかし、
2177 .B return
2178 は、interact を呼出元に復帰させる。一方、
2179 .B inter_return
2180 は、
2181 .B interact
2182 をその呼びだし元内に復帰させる。例えば、"proc foo" は
2183 .B interact
2184 を呼ぶ。interact が、さらに、
2185 .BR inter_return
2186 を実行すると
2187 .B proc foo
2188 が復帰する。(これは、
2189 .B interact
2190 が、
2191 .B interpreter
2192 を呼んで
2193 .B return
2194 とタイプすると、そのinteractは継続するが、
2195 .B inter_return
2196 すると、その呼出元に復帰してしまうということである。)
2197 .IP
2198 .\"O During
2199 .\"O .BR interact ,
2200 .\"O raw mode is used so that all characters may be passed to the current process.
2201 .\"O If the current process does not catch job control signals,
2202 .\"O it will stop if sent a stop signal (by default ^Z).
2203 .\"O To restart it, send a continue signal (such as by "kill \-CONT <pid>").
2204 .\"O If you really want to send a SIGSTOP to such a process (by ^Z),
2205 .\"O consider spawning csh first and then running your program.
2206 .\"O On the other hand, if you want to send a SIGSTOP to
2207 .\"O .B Expect
2208 .\"O itself, first call interpreter (perhaps by using an escape character), and then press ^Z.
2209 .BR interact
2210 の間 raw モードが使用されるので、全ての文字が現プロセスに渡される。
2211 現プロセスがジョブコントロールシグナルを捕まえなければ、
2212 ストップシグナル(デフォルト^Z)で停止する。再スタートするには、
2213 制御シグナルを送る。("kill \-CONT <pid>"とか打って)。
2214 本当に SIGSTOP をプロセスに送りたいなら、csh を spawn してその上で
2215 プロセスを起動すること。
2216 そうでなくて、
2217 .B Expect
2218 そのものに SIGSTOP を送りたいなら、インタプリタを呼び出して
2219 (普通はエスケープ文字)、その後 ^Z を打つこと。
2220 .IP
2221 .\"O String-body pairs can be used as a shorthand for avoiding having
2222 .\"O to enter the interpreter and execute commands interactively.  The previous
2223 .\"O terminal mode is used while the body of a string-body pair is being executed.
2224 string bodyのペアは、インタプリタに入ってコマンドを対話的に実行するのを
2225 避けることを簡単に書くのに使われる。
2226 前の端末モードが、その body を実行する間使用される。
2227 .IP
2228 .\"O For speed, actions execute in raw mode by default.  The
2229 .\"O .B \-reset
2230 .\"O flag resets the terminal to the mode it had before
2231 .\"O .B interact
2232 .\"O was executed (invariably, cooked mode).
2233 .\"O Note that characters entered when the mode is being switched may be lost
2234 .\"O (an unfortunate feature of the terminal driver on some systems).
2235 .\"O The only reason to use
2236 .\"O .B \-reset
2237 .\"O is if your action
2238 .\"O depends on running in cooked mode.
2239 実行速度を上げるには、デフォルトでアクションが raw モードで動くように
2240 する。
2241 .B \-reset
2242 フラグは、端末の持っているモードをリセットする。そうしなければ、
2243 その前に行なった
2244 .B interact
2245 コマンドの端末モード(cooked モードとか)が保持される。
2246 モードが切り替わった時に、それまで打っていた文字が消えてしまうことが
2247 あるので注意すること。(システムによっては、そういう不幸な仕様をした
2248 端末ドライバが動いている。)
2249 .B \-reset
2250 を使うのは、アクションが cooked モードでしか動かない場合だけである。
2251 .IP
2252 .\"O The
2253 .\"O .B \-echo
2254 .\"O flag sends characters that match the following pattern back to the process
2255 .\"O that generated them as each character is read.  This may be useful
2256 .\"O when the user needs to see feedback from partially typed patterns.
2257 .B \-echo
2258 フラグは、一文字づつパターンにマッチする文字を返す。これは、
2259 ユーザーが打つ文字に部分的にマッチしなければならない場合に有効である。
2260 .IP
2261 .\"O If a pattern is being echoed but eventually fails to match,
2262 .\"O the characters are sent to the spawned process.  If the spawned
2263 .\"O process then echoes them, the user will see the characters twice.
2264 .\"O .B \-echo
2265 .\"O is probably only appropriate in situations where the user is
2266 .\"O unlikely to not complete the pattern.  For example, the following
2267 .\"O excerpt is from rftp, the recursive-ftp script, where the user is
2268 .\"O prompted to enter ~g, ~p, or ~l, to get, put, or list the current
2269 .\"O directory recursively.  These are so far away from the normal ftp
2270 .\"O commands, that the user is unlikely to type ~ followed by anything
2271 .\"O else, except mistakenly, in which case, they'll probably just ignore
2272 .\"O the result anyway.
2273 パターンはエコーされたがマッチには失敗した場合、文字列は、spawn された
2274 プロセスに送られる。それから、spawn されたプロセスが文字列を表示し、
2275 ユーザーは文字列を二度見る。
2276 .B \-echo
2277 は、ユーザーがパターンを完成させてくれそうもない場合にだけ有効であろう。
2278 例えば、以下は rftp(リカーシブ ftp スクリプト)からの抜粋だが、ユーザーが
2279 ~g, ~p, ~l を打つとカレントディレクトリから再帰的(リカーシブ)に get,
2280 put, list する。通常の ftp ではこれらの操作ができない。間違って ~ を
2281 打つか、~ の後を間違えた場合、その文字列を無視するようになっている。
2282 .nf
2283
2284     interact {
2285         -echo ~g {getcurdirectory 1}
2286         -echo ~l {getcurdirectory 0}
2287         -echo ~p {putcurdirectory}
2288     }
2289
2290 .fi
2291 .\"O The
2292 .\"O .B \-nobuffer
2293 .\"O flag sends characters that match the following pattern on to
2294 .\"O the output process as characters are read.
2295 .\"O 
2296 .\"O This is useful when you wish to let a program echo back the pattern.
2297 .\"O For example, the following might be used to monitor where a person is
2298 .\"O dialing (a Hayes-style modem).  Each time "atd" is seen the script
2299 .\"O logs the rest of the line.
2300 .\"O .nf
2301 .\"O 
2302 .\"O     proc lognumber {} {
2303 .\"O         interact -nobuffer -re "(.*)\\r" return
2304 .\"O         puts $log "[exec date]: dialed $interact_out(1,string)"
2305 .\"O     }
2306 .\"O 
2307 .\"O     interact -nobuffer "atd" lognumber
2308 .\"O 
2309 .\"O .fi
2310 .B \-nobuffer
2311 フラグは、文字が読まれる度に、その文字をマッチへ送る。
2312
2313 このフラグは、パターンをエコーバックする時に有効である。
2314 例えば、以下は誰かが(ヘイズモデムを)ダイアルするのを監視するのに
2315 使われる。"atd"が見える度にスクリプトが残りのラインをログする。
2316 .nf
2317
2318     proc lognumber {} {
2319         interact -nobuffer -re "(.*)\\r" return
2320         puts $log "[exec date]: dialed $interact_out(1,string)"
2321     }
2322
2323     interact -nobuffer "atd" lognumber
2324
2325 .fi
2326 .IP
2327 .\"O During
2328 .\"O .BR interact ,
2329 .\"O previous use of
2330 .\"O .B log_user
2331 .\"O is ignored.  In particular,
2332 .\"O .B interact
2333 .\"O will force its output to be logged (sent to the standard output)
2334 .\"O since it is presumed the user doesn't wish to interact blindly.
2335 .BR interact
2336 の間、前に使った
2337 .B log_user
2338 は無視される。特に、
2339 .B interact
2340 は、その出力を記録される(標準出力に送られる)。
2341 というのは、ユーザーはエコーバックのない状態でキーを打ちたくはない
2342 だろうと考えるからである。
2343 .IP
2344 .\"O The
2345 .\"O .B \-o
2346 .\"O flag causes any following key-body pairs to be applied to the output of
2347 .\"O the current process.
2348 .\"O This can be useful, for example, when dealing with hosts that
2349 .\"O send unwanted characters during a telnet session.  
2350 .B \-o
2351 フラグは、現プロセスの出力に key body ペアの key を結びつける。
2352 こんな場合に便利である。例えば、telnet セッション中に望まない文字を
2353 送ってくるホストを扱う場合である。
2354 .IP
2355 .\"O By default, 
2356 .\"O .B interact
2357 .\"O expects the user to be writing stdin and reading stdout of the
2358 .\"O .B Expect
2359 .\"O process
2360 .\"O itself.
2361 .\"O The
2362 .\"O .B \-u
2363 .\"O flag (for "user") makes
2364 .\"O .B interact
2365 .\"O look for the user as the process named by its argument
2366 .\"O (which must be a spawned id).  
2367 デフォルトでは、
2368 .B interact
2369 は、ユーザーが
2370 .B Expect
2371 プロセス自身の標準入力に書き込み、標準出力を見ていると思っている。
2372 .B \-u
2373 フラグ("user"のu)は
2374 .B interact
2375 に、引数で付けられた名前(spawned id である)のプロセスをユーザーとして
2376 扱う。
2377 .IP
2378 .\"O This allows two unrelated processes to be joined
2379 .\"O together without using an explicit loop.  To aid in debugging, Expect
2380 .\"O diagnostics always go to stderr (or stdout for certain logging and
2381 .\"O debugging information).  For the same reason, the
2382 .\"O .B interpreter
2383 .\"O command will read interactively from stdin.
2384 これにより、変なループなしに2つの無関係なプロセスを結合させることが
2385 できる。デバッグする時の助けとして、Expect は常に診断結果を stderr
2386 へ送る。(ある種のログとデバッグ情報は stdout に送られる)。
2387 同じ理由で、
2388 .B interpreter
2389 コマンドは、stdin からデータを読む。
2390 .IP
2391 .\"O For example, the following fragment creates a login process.
2392 .\"O Then it dials the user (not shown), and finally connects the two together.
2393 .\"O Of course, any process may be substituted for login.
2394 .\"O A shell, for example, would allow the user to work without supplying an
2395 .\"O account and password.
2396 例えば、以下の断片はログインプロセスを作る。そして、(表示されない)
2397 ユーザーにダイアルし、両方の接続を行なう。
2398 もちろん、loginをどんなプロセスに変えても良い。例えば、シェルなら、ア
2399 カウントとパスワードを与えなくてもユーザーが起動できる。
2400 .nf
2401
2402     spawn login
2403     set login $spawn_id
2404     spawn tip modem
2405     # dial back out to user
2406     # connect user to login
2407     interact \-u $login
2408
2409 .fi
2410 .\"O To send output to multiple processes, list each spawn id list prefaced by a
2411 .\"O .B \-output
2412 .\"O flag.  Input for a group of output spawn ids may be determined
2413 .\"O by a spawn id list prefaced by a
2414 .\"O .B \-input
2415 .\"O flag.  (Both
2416 .\"O .B \-input
2417 .\"O and
2418 .\"O .B \-output
2419 .\"O may take lists in the same form as the
2420 .\"O .B \-i
2421 .\"O flag in the
2422 .\"O .B expect
2423 .\"O command, except that any_spawn_id is not meaningful in
2424 .\"O .BR interact .)
2425 .\"O All following flags and
2426 .\"O strings (or patterns) apply to this input until another -input flag appears.
2427 .\"O If no
2428 .\"O .B \-input
2429 .\"O appears,
2430 .\"O .B \-output
2431 .\"O implies "\-input $user_spawn_id \-output".
2432 .\"O (Similarly, with patterns that do not have
2433 .\"O .BR \-input .)
2434 .\"O If one
2435 .\"O .B \-input
2436 .\"O is specified, it overrides $user_spawn_id.  If a second
2437 .\"O .B \-input
2438 .\"O is specified,
2439 .\"O it overrides $spawn_id.  Additional
2440 .\"O .B \-input
2441 .\"O flags may be specified.
2442 .\"O 
2443 .\"O The two implied input processes default to having their outputs specified as
2444 .\"O $spawn_id and $user_spawn_id (in reverse).  
2445 .\"O If a
2446 .\"O .B \-input
2447 .\"O flag appears
2448 .\"O with no
2449 .\"O .B \-output
2450 .\"O flag, characters from that process are discarded.
2451 .\"O 
2452 .\"O The
2453 .\"O .B \-i
2454 .\"O flag introduces a replacement for the current spawn_id when no
2455 .\"O other
2456 .\"O .B \-input
2457 .\"O or
2458 .\"O .B \-output
2459 .\"O flags are used.  A \-i flag implies a \-o flag.
2460 .\"O 
2461 複数のプロセスへの出力を行なうため、
2462 .B \-output
2463 フラグを前につけた各 spawn id のセットがリストされる。
2464 出力 spawn id の組への入力は、
2465 .B \-input
2466 フラグによって決定される。
2467 (
2468 .B \-input
2469
2470 .B \-output
2471 フラグは両方とも
2472 .B expect
2473 コマンドの
2474 .B \-i
2475 フラグと同じ書式である。(
2476 .BR interact
2477 内の any_spawn_id は意味がない点を除く。)
2478 以下のフラグと文字列(あるいはパターン)は全て、別の -input フラグが現れるまで
2479 この入力を適用する。
2480 .B \-input
2481 が現れなかった場合、
2482 .B \-output
2483 は "\-input $user_spawn_id \-output"
2484 を行なう。
2485 (
2486 .BR \-input
2487 を持たないパターンも同様である。)
2488 .B \-input
2489 が一つだけ指示されると、$user_spawn_id はその値で置き換わる。
2490 二つめの
2491 .B \-input
2492 が指示されると、$spawn_id が置き換わる。
2493 以降の
2494 .B \-input
2495 フラグも指定できる。
2496
2497 2つの入力プロセスはデフォルトで $spawn_id と $user_spawn_id に出力される。
2498 もし、
2499 .B \-input
2500 フラグが
2501 .B \-output
2502 フラグなしで指定された場合、プロセスからの文字は捨てられる。
2503
2504 .B \-i
2505 フラグは、現在の spawn_id を書き換える。
2506 ただし、
2507 .B \-input
2508 または
2509 .B \-output
2510 フラグが使われていない場合である。\-i フラグは \-o フラグを含む。
2511
2512 .\"O It is possible to change the processes that are being interacted with
2513 .\"O by using indirect spawn ids.  (Indirect spawn ids are described in the
2514 .\"O section on the expect command.)  Indirect spawn ids may be specified
2515 .\"O with the -i, -u, -input, or -output flags.
2516 間接 spawn id を使って会話しているプロセスを切替えることが可能である。
2517 (間接 spawn id は、expect コマンドの項で説明した)
2518 間接 spawn id は、-i, -u, -input, -output フラグで指定できる。
2519 .TP
2520 .B interpreter " [args]"
2521 .\"O causes the user to be interactively prompted for
2522 .\"O .B Expect
2523 .\"O and Tcl commands.
2524 .\"O The result of each command is printed.
2525 は、ユーザーに
2526 .B Expect
2527 と Tcl コマンドのためのプロンプトを表示する。
2528 各コマンドの結果が表示される。
2529 .IP
2530 .\"O Actions such as
2531 .\"O .B break
2532 .\"O and
2533 .\"O .B continue
2534 .\"O cause control structures (i.e.,
2535 .\"O .BR for ,
2536 .\"O .BR proc )
2537 .\"O to behave in the usual way.
2538 .\"O However
2539 .\"O .B return
2540 .\"O causes interpreter to return to its caller, while
2541 .\"O .B inter_return
2542 .\"O causes
2543 .\"O .B interpreter
2544 .\"O to cause a return in its caller.  For example, if "proc foo" called
2545 .\"O .B interpreter
2546 .\"O which then executed the action
2547 .\"O .BR inter_return ,
2548 .\"O .B proc foo
2549 .\"O would return.
2550 .\"O Any other command causes
2551 .\"O .B interpreter
2552 .\"O to continue prompting for new commands.
2553 .B break
2554
2555 .B continue
2556 は制御構造(すなわち、
2557 .BR for
2558 .BR proc
2559 )で、通常通りに動く。
2560 しかし、
2561 .B return
2562 は、呼出元への復帰を行なうのに対し、
2563 .B inter_return
2564
2565 .B interpreter
2566 を、呼出元を復帰させる。たとえば、
2567 "proc foo" は、
2568 .B interpreter
2569 を呼び、
2570 .BR inter_return
2571 を実行し
2572 .B proc foo
2573 が復帰する。
2574 他のコマンドは
2575 .B interpreter
2576 に新しいコマンドのためのプロンプトを表示し続ける。
2577 .IP
2578 .\"O By default, the prompt contains two integers.
2579 .\"O The first integer describes the depth of
2580 .\"O the evaluation stack (i.e., how many times Tcl_Eval has been called).  The
2581 .\"O second integer is the Tcl history identifier.  The prompt can be set by
2582 .\"O defining a procedure called "prompt1" whose return value becomes the next
2583 .\"O prompt.  If a statement has open quotes, parens, braces, or brackets, a
2584 .\"O secondary prompt (by default "+> ") is issued upon newline.  The secondary
2585 .\"O prompt may be set by defining a procedure called "prompt2".
2586 デフォルトでは、プロンプトは 2 つの整数を含んでいる。
2587 最初の数は評価スタックの深さ(つまり、何回 Tcl_Eval が呼ばれたか)
2588 2番めの数は、Tcl ヒストリ識別番号である。プロンプトは
2589 "prompt1"と呼ばれるプロシジャを定義することで設定できる。
2590 このプロシジャの帰り値が次のプロンプトとなる。
2591 記述に開きクオート、括弧、ブレース、ブラケットがあると、次の行には
2592 第 2 プロンプトが現れる(デフォルトは "+> ")。第 2 プロンプトは
2593 "prompt2"と呼ばれるプロシジャを定義することで設定できる。
2594 .IP
2595 .\"O During
2596 .\"O .BR interpreter ,
2597 .\"O cooked mode is used, even if the its caller was using raw mode.
2598 .BR interpreter
2599 の間は、呼出元が raw モードであったとしても、cooked モードが使われる。
2600 .IP
2601 .\"O If stdin is closed,
2602 .\"O .B interpreter
2603 .\"O will return unless the
2604 .\"O .B \-eof
2605 .\"O flag is used, in which case the subsequent argument is invoked.
2606 stdin が閉じられると、
2607 .B interpreter
2608
2609 .B \-eof
2610 フラグが使われていない限り復帰する。
2611 使われている場合は引き続く引数を実行する。
2612 .TP
2613 .BI log_file " [args] [[\-a] file]"
2614 .\"O or
2615 .\"O .B \-leaveopen
2616 .\"O flags.  This is similar to the
2617 .\"O .B spawn
2618 .\"O command.  (See
2619 .\"O .B spawn
2620 .\"O for more info.)
2621 .\"O 
2622 .\"O The
2623 .\"O .B \-a
2624 .\"O flag forces output to be logged that was suppressed by the
2625 .\"O .B log_user
2626 .\"O command.
2627 .\"O 
2628 .\"O By default, the
2629 .\"O .B log_file
2630 .\"O command
2631 .\"O .I appends
2632 .\"O to old files rather than truncating them,
2633 .\"O for the convenience of being able to turn logging off and on multiple
2634 .\"O times in one session.
2635 .\"O To truncate files, use the
2636 .\"O .B \-noappend
2637 .\"O flag.
2638 .\"O 
2639 .\"O The
2640 .\"O .B -info
2641 .\"O flag causes log_file to return a description of the
2642 .\"O most recent non-info arguments given.
2643 ファイル名が与えられると、
2644 .B log_file
2645 は、(現時点からの)セッションのログをそのファイルに採取する。
2646 引数がなければ、
2647 .B log_file
2648 は記録をやめる。使っていたログファイルはクローズされる。
2649
2650 ファイル名の代わりに、Tcl ファイル識別子を指定すると、
2651 .B \-open
2652
2653 .B \-leaveopen
2654 フラグが使える。
2655 .B spawn
2656 コマンドと同様だ(より詳しくは、
2657 .B spawn
2658 を参照)
2659
2660 .B \-a
2661 フラグは、
2662 .B log_user
2663 コマンドによって抑止されたログに出力を強制するものである。
2664
2665 デフォルトでは、
2666 .B log_file
2667 コマンドは古い記録を消して書き直したりせずに
2668 .I 追記
2669 する。
2670 ログオフや複数のログを書く時に都合が良いように。
2671 ファイルを消して書き直す時は
2672 .B \-noappend
2673 フラグを使う。
2674
2675 .B -info
2676 フラグは、最後にログした内容を返す(最後が-infoフラグ付きだったら、
2677 その前の内容)。
2678 .TP
2679 .BI log_user " -info|0|1"
2680 .\"O By default, the send/expect dialogue is logged to stdout
2681 .\"O (and a logfile if open).
2682 .\"O The logging to stdout is disabled by the command "log_user 0"
2683 .\"O and reenabled by "log_user 1".  Logging to the logfile is unchanged.
2684 デフォルトでは、send/expect ダイアログは標準出力にロギングされる。
2685 (開いていればログファイルにもロギングされる。)
2686 "log_user 0"とすると、標準出力へのロギングが抑止される。
2687 "log_user 1"とすると、復旧する。ログファイルへの記録については
2688 変更はない。
2689
2690 .\"O The
2691 .\"O .B -info
2692 .\"O flag causes log_user to return a description of the
2693 .\"O most recent non-info arguments given.
2694 .B -info
2695 フラグは、最後にログした内容を返す(最後が -info フラグ付きだったら、
2696 その前の内容)。
2697 .TP
2698 .BI match_max " [\-d] [\-i spawn_id] [size]"
2699 .\"O defines the size of the buffer (in bytes) used internally by
2700 .\"O .BR expect .
2701 .\"O With no
2702 .\"O .I size
2703 .\"O argument, the current size is returned.
2704 は、バッファサイズを(バイト単位で)定義する。このバッファは、
2705 .BR expect
2706 の内部で使われる。
2707 引数
2708 .I size
2709 がないと、現在のサイズを復帰する。
2710 .\"O .IP
2711 .\"O With the
2712 .\"O .B \-d
2713 .\"O flag, the default size is set.  (The initial default is 2000.)
2714 .\"O With the
2715 .\"O .B \-i
2716 .\"O flag, the size is set for the named spawn id, otherwise it is set for
2717 .\"O the current process.
2718 .IP
2719 .B \-d
2720 フラグを指示すると、デフォルトサイズが設定される。(初期状態の
2721 デフォルト値は 2000。)
2722 .B \-i
2723 フラグを指示すると、名前つき spawn id に対してサイズが設定される。
2724 指定しなければ、カレントプロセスに対して設定される。
2725 .TP
2726 .BI overlay " [\-# spawn_id] [\-# spawn_id] [...] program [args]"
2727 .\"O executes
2728 .\"O .IR "program args"
2729 .\"O in place of the current
2730 .\"O .B Expect
2731 .\"O program, which terminates.
2732 .\"O A bare hyphen argument forces a hyphen in front of the command name as if
2733 .\"O it was a login shell.
2734 .\"O All spawn_ids are closed except for those named as arguments.  These
2735 .\"O are mapped onto the named file identifiers.
2736 は、
2737 .IR "program args"
2738 を現在の
2739 .B Expect
2740 プログラム上で実行する。現在の Expect プログラムは終了する。
2741 ただのハイフンが引数に指定されると、コマンド名の前にハイフンをつけて
2742 ログインシェルとして扱う。
2743 全てのクローズ中の spawn_id は、引数に使われた文字列を待つ。
2744 .IP
2745 .\"O Spawn_ids are mapped to file identifiers for the new program to inherit.
2746 .\"O For example, the following line runs chess and allows it to be
2747 .\"O controlled by the current process \- say, a chess master.
2748 Spawn_id は、新しいプログラムに継承させるためのファイル ID に
2749 マップされる。例えば、以下の行はチェスを行ない、chess master
2750 という現プロセスに制御させる。
2751 .nf
2752
2753     overlay \-0 $spawn_id \-1 $spawn_id \-2 $spawn_id chess
2754
2755 .fi
2756 .\"O This is more efficient than
2757 .\"O "interact \-u", however, it sacrifices the ability to do programmed
2758 .\"O interaction since the
2759 .\"O .B Expect
2760 .\"O process is no longer in control.
2761 .\"O .IP
2762 .\"O Note that no controlling terminal is provided.  Thus, if you
2763 .\"O disconnect or remap standard input, programs that do
2764 .\"O job control (shells, login, etc) will not function properly.
2765 これは、
2766 "interact \-u"
2767 とするよりも効果的である。しかし、
2768 .B Expect
2769 プロセスが制御していないのでプログラム能力が犠牲となる。
2770 .IP
2771 制御されない端末ができてしまうことに注意すること。それで、
2772 disconnect するか標準入力をリマップするとジョブ制御プログラム
2773 (シェル、ログインなど)が正しく機能しない。
2774 .TP
2775 .BI parity " [\-d] [\-i spawn_id] [value]"
2776 .\"O defines whether parity should be retained or stripped from the output of
2777 .\"O spawned processes.  If
2778 .\"O .I value
2779 .\"O is zero, parity is stripped, otherwise it is not stripped.
2780 .\"O With no
2781 .\"O .I value
2782 .\"O argument, the current value is returned.
2783 .\"O .IP
2784 .\"O With the
2785 .\"O .B \-d
2786 .\"O flag, the default parity value is set.  (The initial default is 1, i.e., 
2787 .\"O parity is not stripped.)
2788 .\"O With the
2789 .\"O .B \-i
2790 .\"O flag, the parity value is set for the named spawn id, otherwise it is set for
2791 .\"O the current process.
2792 は、spawn idの出力からパリティを保持するか取り除くかを設定する。
2793 .I value
2794 が 0 であれば、パリティは取り除かれる。
2795 それ以外の場合、取り除かれない。
2796 .I value
2797 が指定されない場合、現在の値が復帰する。
2798 .IP
2799 .B \-d
2800 フラグは、パリティのデフォルト値を設定する。(イニシャル時のデフォルト値は
2801 1 である。すなわち、パリティが取り除かれる。)
2802 .B \-i
2803 フラグを指示すると、パリティの値が引数の名前つきの spawn id に対して
2804 設定される。引数がなければ現在のプロセスに対して設定される。
2805 .TP
2806 .BI remove_nulls " [\-d] [\-i spawn_id] [value]"
2807 .\"O .I value
2808 .\"O is 1, nulls are removed.  If
2809 .\"O .I value
2810 .\"O is 0, nulls are not removed.
2811 .\"O With no
2812 .\"O .I value
2813 .\"O argument, the current value is returned.
2814 .\"O .IP
2815 .\"O With the
2816 .\"O .B \-d
2817 .\"O flag, the default value is set.  (The initial default is 1, i.e., 
2818 .\"O nulls are removed.)
2819 .\"O With the
2820 .\"O .B \-i
2821 .\"O flag, the value is set for the named spawn id, otherwise it is set for
2822 .\"O the current process.
2823 .\"O 
2824 .\"O Whether or not nulls are removed,
2825 .\"O .B Expect
2826 .\"O will record null bytes to the log and stdout.
2827 は、前にパターンマッチしたあるいは
2828 .I expect_out 
2829
2830 .IR interact_out
2831 に保存されている spawn されたプロセスの出力からヌルを保持するか取り除くかを
2832 設定する。
2833 .I value
2834 が 1 なら、ヌルは取り除かれる。もし、
2835 .I value
2836 が 0 なら、ヌルは取り除かれる。
2837 .I value
2838 がなければ、現在の値が復帰する。
2839 .IP
2840 .B \-d
2841 フラグは、デフォルト値を設定する。(イニシャルのデフォルト値は、
2842 1 である。それゆえ、ヌルは取り除かれる。)
2843 .B \-i
2844 フラグは、名前つきの spawn id に対して値を設定する。なければ、
2845 現プロセスに対して設定する。
2846
2847 ヌルを取り除くかどうかによらず、
2848 .B Expect
2849 は、ログと標準出力にはヌルが記録される。
2850 .TP
2851 .BI send " [\-flags] string"
2852 .\"O Sends
2853 .\"O .IR string
2854 .\"O to the current process.
2855 .IR string
2856 を現プロセスに送る。
2857 .\"O For example, the command
2858 例えば、以下のコマンド:
2859 .nf
2860
2861     send "hello world\\r"
2862
2863 .fi
2864 .\"O sends the characters, h e l l o <blank> w o r l d <return> to the 
2865 .\"O current process.  
2866 .\"O (Tcl includes a printf-like command (called
2867 .\"O .BR format )
2868 .\"O which can build arbitrarily complex strings.)
2869 は、文字 h e l l o <blank> w o r l d <return>  を現在のプロセスに
2870 送る。
2871 (Tcl は、printf に似たコマンド (
2872 .BR format
2873 と呼ばれる )を持っていて、複雑な文字列を組み立てることができる。)
2874 .IP
2875 .\"O Characters are sent immediately although programs with line-buffered input
2876 .\"O will not read the characters until a return character is sent.  A return
2877 .\"O character is denoted "\\r".
2878 .\"O 
2879 .\"O The
2880 .\"O .B \-\-
2881 .\"O flag forces the next argument to be interpreted as a string rather than a flag.
2882 .\"O Any string can be preceded by "\-\-" whether or not it actually looks
2883 .\"O like a flag.  This provides a reliable mechanism to specify variable strings
2884 .\"O without being tripped up by those that accidentally look like flags.
2885 .\"O (All strings starting with "-" are reserved for future options.)
2886 .\"O 
2887 .\"O The
2888 .\"O .B \-i
2889 .\"O flag declares that the string be sent to the named spawn_id.
2890 .\"O If the spawn_id is
2891 .\"O .IR user_spawn_id ,
2892 .\"O and the terminal is in raw mode, newlines in the string are translated
2893 .\"O to return-newline
2894 .\"O sequences so that they appear as if the terminal was in cooked mode.
2895 .\"O The
2896 .\"O .B \-raw
2897 .\"O flag disables this translation.
2898 .\"O 
2899 .\"O The
2900 .\"O .BR \-null
2901 .\"O flag sends null characters (0 bytes).  By default, one null is sent.
2902 .\"O An integer may follow the
2903 .\"O .BR \-null
2904 .\"O to indicate how many nulls to send.
2905 .\"O 
2906 .\"O The
2907 .\"O .B \-break
2908 .\"O flag generates a break condition.  This only makes sense if the spawn
2909 .\"O id refers to a tty device opened via "spawn -open".  If you have
2910 .\"O spawned a process such as tip, you should use tip's convention for
2911 .\"O generating a break.
2912 .\"O 
2913 .\"O The
2914 .\"O .B \-s
2915 .\"O flag forces output to be sent "slowly", thus avoid the common situation
2916 .\"O where a computer outtypes an input buffer that was designed for a
2917 .\"O human who would never outtype the same buffer.  This output is
2918 .\"O controlled by the value of the variable "send_slow" which takes a two
2919 .\"O element list.  The first element is an integer that describes the
2920 .\"O number of bytes to send atomically.  The second element is a real
2921 .\"O number that describes the number of seconds by which the atomic sends
2922 .\"O must be separated.  For example, "set send_slow {10 .001}" would force
2923 .\"O "send \-s" to send strings with 1 millisecond in between each 10
2924 .\"O characters sent.
2925 .\"O 
2926 .\"O The
2927 .\"O .B \-h
2928 .\"O flag forces output to be sent (somewhat) like a human actually typing.
2929 .\"O Human-like delays appear between the characters.  (The algorithm is
2930 .\"O based upon a Weibull distribution, with modifications to suit this
2931 .\"O particular application.)  This output is controlled by the value of
2932 .\"O the variable "send_human" which takes a five element list.  The first
2933 .\"O two elements are average interarrival time of characters in seconds.
2934 .\"O The first is used by default.  The second is used at word endings, to
2935 .\"O simulate the subtle pauses that occasionally occur at such
2936 .\"O transitions.  The third parameter is a measure of variability where .1
2937 .\"O is quite variable, 1 is reasonably variable, and 10 is quite
2938 .\"O invariable.  The extremes are 0 to infinity.  The last two parameters
2939 .\"O are, respectively, a minimum and maximum interarrival time.
2940 .\"O The minimum and maximum are used last and "clip" the final time.
2941 .\"O The ultimate average can be quite different from the given average
2942 .\"O if the minimum and maximum clip enough values.
2943 文字は直ちに送られる。ただし、入力にラインバッファのあるプログラムでは、
2944 リターンコードが送られるまで文字が読まれない。リターンコードは、
2945 "\\r"と表記する。
2946
2947 .B \-\-
2948 フラグは、続く引数をフラグと解釈せず文字列として解釈される。
2949 全体としてフラグに見えなくても"\-\-"が前についた文字列はフラグとして
2950 扱われてしまう。このフラグは処理されていない文字列がフラグとして
2951 扱われるのを防ぐ。
2952 ("-"で始まる文字は全て将来のオプションとして予約されている。)
2953
2954 .B \-i
2955 フラグは、名前つきの spawn_id に文字列を送ることを宣言する。
2956 その spawn_id が
2957 .IR user_spawn_id
2958 であれば、端末はraw モードに入り、文字列中の改行が復帰改行シーケンスに
2959 変換される。それで、外からは 端末が cooked モードとなっているように
2960 見える。
2961 .B \-raw
2962 フラグは、この変換を抑止する。
2963
2964 .BR \-null
2965 フラグは、ヌル文字を送る(0 バイト)。デフォルトでは、ヌル文字を
2966 1つ送る。
2967 .BR \-null
2968 に続く整数はヌル文字をいくつ送るかを指示する。
2969
2970 .B \-break
2971 フラグは、ブレーク状態を作る。spawn id が"spawn -open"で指示した
2972 tty デバイスを参照する場合のみ意味がある。tip などのプロセスを
2973 spawn する場合、tip の都合で ブレーク状態を作るべきである。
2974
2975 .B \-s
2976 フラグは、出力を強制的に"遅く"する。結果、コンピュータが打ち込んでいる
2977 バッファに人間が打ち込んでしまう状況を避けることができる。この出力は
2978 変数"send_slow"の値で制御される。この変数は二つの要素を持つリストである。
2979 最初の要素は、アトミックに送るバイト数である。2 番めの要素はアトミックに送る
2980 間隔(秒)である。例えば、 "set send_slow {10 .001}" は "send \-s" に 
2981 10 文字送る毎に1ミリ秒待つように指示する。
2982
2983 .B \-h
2984 フラグは、人間の実際の入力に似せて send を行なう。(アルゴリズムは、
2985 Weibull distribution に基づいていて、この特定のアプリケーション Expect? に
2986 合わせるための修正が行なわれている。)
2987 この出力は変数"send_human"の値で制御されていて、この変数は 5 つの要素から
2988 なるリストで最初の 2 つの要素は文字間の平均インターバル時間(秒)である。
2989 1 つめがデフォルト値で、2 つめが(通常発生する微妙な待ち時間を表現する)
2990 単語の終りの値である。3 つめの要素は変動率である。
2991 .1 はよく変動する。 1 は妥当な変動率である。 10 だと全然変化しない。
2992 可能な値は 0 から 無限大である。最後の 2 つのパラメタは、それぞれ、
2993 インターバル時間の最小値と最大値である。この 2 つの値は最後に使われて、
2994 最終時刻をクリップする。この 2 値が違うと究極の平均は与えられた平均とは、
2995 全く違ったものになる。
2996
2997 .\"O As an
2998 .\"O example, the following command emulates a fast and
2999 .\"O consistent typist:
3000 例として、続くコマンドが一定の速度で速く打つタイピストを
3001 エミュレートする:
3002 .nf
3003
3004     set send_human {.1 .3 1 .05 2}
3005     send \-h "I'm hungry.  Let's do lunch."
3006
3007 .fi
3008 .\"O while the following might be more suitable after a hangover:
3009 ハングさせてしまった後は、以下のようにした方が良いだろう。:
3010 .nf
3011
3012     set send_human {.4 .4 .2 .5 100}
3013     send \-h "Goodd party lash night!"
3014
3015 .fi
3016 .\"O Note that errors are not simulated, although you can set up error
3017 .\"O correction situations yourself by embedding mistakes and corrections
3018 .\"O in a send argument.
3019 .\"O 
3020 .\"O The flags for sending null characters, for sending breaks, for forcing slow
3021 .\"O output and for human-style output are mutually exclusive. Only the one
3022 .\"O specified last will be used. Furthermore, no
3023 .\"O .I string
3024 .\"O argument can be specified with the flags for sending null characters or breaks.
3025 .\"O 
3026 .\"O It is a good idea to precede the first
3027 .\"O .B send
3028 .\"O to a process by an
3029 .\"O .BR expect .
3030 .\"O .B expect
3031 .\"O will wait for the process to start, while
3032 .\"O .B send
3033 .\"O cannot.
3034 .\"O In particular, if the first
3035 .\"O .B send
3036 .\"O completes before the process starts running,
3037 .\"O you run the risk of having your data ignored.
3038 .\"O In situations where interactive programs offer no initial prompt,
3039 .\"O you can precede
3040 .\"O .B send
3041 .\"O by a delay as in:
3042 send にエラーや修正を埋め込んであっても、
3043 エラーはシミュレートされない点に注意すること。
3044
3045 ブレークを送るためや、ゆっくりした出力を行なったり、人間が出力したように
3046 見せかけるためにヌル文字を送るフラグは相互排他される。
3047 最後に指定されたものだけが使われる。それ以上は、
3048 .I string
3049 の引数が、ヌル文字あるいはブレークを送るフラグとして指定できる。
3050
3051 最初の
3052 .B send
3053 より前に
3054 .B expect
3055 を置いた方が良い。
3056 .B expect
3057 は、プロセスが始まるのを待てるが、
3058 .B send
3059 は待てない。
3060 特に、最初の
3061 .B send
3062 は、プロセスが走り始める前に完了する。あなたのデータが無視される
3063 危険がある。
3064 最初にプロンプトを表示しないような対話的なプログラムでは、
3065 次のように
3066 .B send
3067 の前にディレイをつけることができる:
3068 .nf
3069
3070 .\"O     # To avoid giving hackers hints on how to break in,
3071 .\"O     # this system does not prompt for an external password.
3072 .\"O     # Wait for 5 seconds for exec to complete
3073     # どのように破るかのヒントをハッカーに与えてしまわないように、
3074     # このシステムでは外部のパスワードに対するプロンプトを提供しない。
3075     # exec が完了するのを 5 秒待て。
3076     spawn telnet very.secure.gov
3077     sleep 5
3078     send password\\r
3079
3080 .fi
3081 .\"O .B exp_send
3082 .\"O is an alias for
3083 .\"O .BI send .
3084 .\"O If you are using Expectk or some other variant of Expect in the Tk environment,
3085 .\"O .B send
3086 .\"O is defined by Tk for an entirely different purpose.
3087 .\"O .B exp_send
3088 .\"O is provided for compatibility between environments.
3089 .\"O Similar aliases are provided for other Expect's other send commands.
3090 .B exp_send
3091
3092 .B send
3093 のエイリアスである。あなたが Expectk か、Tk 環境で動く Expect の他の変種を
3094 使っている場合、
3095 .B send
3096 は、全く異なった目的のために使われている。
3097 .B exp_send
3098 が、両環境の間での互換性のために提供されている。
3099 似たようなエイリアスが他の Expect の他の send コマンドのために提供されている。
3100 .TP
3101 .BI send_error " [\-flags] string"
3102 .\"O is like
3103 .\"O .BR send ,
3104 .\"O except that the output is sent to stderr rather than the current
3105 .\"O process.
3106 .BR send
3107 と似たようなもので、現プロセスでなく stderr に出力される。
3108 .TP
3109 .BI send_log " [\--] string"
3110 .\"O is like
3111 .\"O .BR send ,
3112 .\"O except that the string is only sent to the log file (see
3113 .\"O .BR log_file .)
3114 .\"O The arguments are ignored if no log file is open.
3115 .BR send
3116 と似たようなもので、ログファイルだけに string を送る。(
3117 .BR log_file
3118 を参照。) 引数はログファイルが open されていなければ無視される。
3119 .TP
3120 .BI send_tty " [\-flags] string"
3121 .\"O is like
3122 .\"O .BR send ,
3123 .\"O except that the output is sent to /dev/tty rather than the current
3124 .\"O process.
3125 .BR send
3126 と似たようなもので、現プロセスでなく /dev/tty へ出力を送る。
3127 .TP
3128 .BI send_user " [\-flags] string"
3129 .\"O except that the output is sent to stdout rather than the current
3130 .\"O process.
3131 .BR send
3132 と似たようなもので、現プロセスでなく標準出力へ出力を送る。
3133 .TP
3134 .BI sleep " seconds"
3135 .\"O causes the script to sleep for the given number of seconds.
3136 .\"O Seconds may be a decimal number.  Interrupts (and Tk events if you
3137 .\"O are using Expectk) are processed while Expect sleeps.
3138 は、与えられた数字の秒数だけスクリプトがスリープする。
3139 seconds は、10進数だけが許される。
3140 (Expectk を使っている場合、Tkのイベントと)割り込みは、Expectが
3141 スリープしている間も処理される。
3142 .TP
3143 .BI spawn " [args] program [args]"
3144 .\"O The process described by
3145 .\"O .I spawn_id
3146 .\"O is considered the
3147 .\"O .IR "current process" .
3148 .\"O .I spawn_id
3149 .\"O may be read or written, in effect providing job control.
3150 .IR "program args"
3151 を走らせる新しいプロセスを生成する。その標準入力と標準出力は
3152 Expect に結びつけられる。それで、他の
3153 .B Expect
3154 コマンドで読んだり書いたりできる。
3155 接続は
3156 .B close
3157 によって、あるいは、プロセスそのものがファイル ID の
3158 いずれかをクローズした場合、破壊される。
3159 .IP
3160 プロセスは
3161 .BR spawn
3162 によって始められる。変数
3163 .I spawn_id
3164 には、そのプロセスへの参照を行なう識別子が設定される。
3165 .I spawn_id
3166 によって記述されるプロセスは
3167 .IR "current process"
3168 が考慮される。
3169 .I spawn_id
3170 は、読んでも書いても良く、効果的なジョブ制御を提供する。
3171 .\"O .IP
3172 .\"O .I user_spawn_id
3173 .\"O is a global variable containing a descriptor which refers to the user.
3174 .\"O For example, when
3175 .\"O .I spawn_id
3176 .\"O is set to this value,
3177 .\"O .B expect
3178 .\"O behaves like
3179 .\"O .BR expect_user .
3180 .\"O 
3181 .\"O .I
3182 .\"O .I error_spawn_id
3183 .\"O is a global variable containing a descriptor which refers to the standard
3184 .\"O error.
3185 .\"O For example, when
3186 .\"O .I spawn_id
3187 .\"O is set to this value,
3188 .\"O .B send
3189 .\"O behaves like
3190 .\"O .BR send_error .
3191 .IP
3192 .I user_spawn_id
3193 はユーザーを参照する識別子の入ったグローバル変数である。
3194 例えば、
3195 .I spawn_id
3196 が、この値に設定された場合、
3197 .B expect
3198 は、
3199 .BR expect_user
3200 のような動きをする。
3201
3202 .I
3203 .I error_spawn_id
3204 は、標準エラー出力を参照する識別子の入ったグローバル変数である。
3205 例えば、
3206 .I spawn_id
3207 が、この値に設定された場合、
3208 .B send
3209 は、
3210 .BR send_error
3211 のような動きをする。
3212 .IP
3213 .\"O .I tty_spawn_id
3214 .\"O is a global variable containing a descriptor which refers to /dev/tty.
3215 .\"O If /dev/tty does not exist (such as in a cron, at, or batch script), then
3216 .\"O .I tty_spawn_id
3217 .\"O is not defined.  This may be tested as:
3218 .I tty_spawn_id
3219 は、/dev/tty を参照する識別子の入ったグローバル変数である。
3220 /dev/tty が存在しない(cron, at, バッチスクリプトの中)場合、
3221 .I tty_spawn_id
3222 は定義されない。以下のように確認することができる。:
3223 .nf
3224
3225     if {[info vars tty_spawn_id]} {
3226         # /dev/tty exists
3227     } else {
3228         # /dev/tty doesn't exist
3229         # probably in cron, batch, or at script
3230     }
3231
3232 .fi
3233 .IP
3234 .\"O .B spawn
3235 .\"O returns the UNIX process id.  If no process is spawned, 0 is returned.
3236 .\"O The variable
3237 .\"O .I spawn_out(slave,name)
3238 .\"O is set to the name of the pty slave device.
3239 .B spawn
3240 UNIX プロセス ID を復帰する。spawn されたプロセスがない場合、0 が
3241 復帰する。変数
3242 .I spawn_out(slave,name)
3243 は pty スレーブデバイスの名前に設定される。
3244 .IP
3245 .\"O By default,
3246 .\"O .B spawn
3247 .\"O echoes the command name and arguments.  The
3248 .\"O .B \-noecho
3249 .\"O flag stops
3250 .\"O .B spawn
3251 .\"O from doing this.
3252 デフォルトでは、
3253 .B spawn
3254 はコマンド名と引数をエコーする。
3255 .B \-noecho
3256 フラグで
3257 .B spawn
3258 がこうするのを止められる。
3259 .IP
3260 .\"O The
3261 .\"O .B \-console
3262 .\"O flag causes console output to be redirected to the spawned process.
3263 .\"O This is not supported on all systems.
3264 .\"O 
3265 .\"O Internally,
3266 .\"O .B spawn
3267 .\"O uses a pty, initialized the same way as the user's tty.  This is further
3268 .\"O initialized so that all settings are "sane" (according to stty(1)).
3269 .\"O If the variable
3270 .\"O .I stty_init
3271 .\"O is defined, it is interpreted in the style of stty arguments
3272 .\"O as further configuration.
3273 .\"O For example, "set stty_init raw" will cause further spawned processes's
3274 .\"O terminals to start in raw mode.
3275 .\"O .B \-nottycopy
3276 .\"O skips the initialization based on the user's tty.
3277 .\"O .B \-nottyinit
3278 .\"O skips the "sane" initialization.
3279 .B \-console
3280 フラグは、コンソールへの出力を起こし、spawn されたプロセスへの
3281 リダイレクトされる。この機能は未サポートのシステムがある。
3282
3283 内部的に、
3284 .B spawn
3285 は pty を使い、ユーザーの tty と同じように初期化される。これは、かなり
3286 初期化してしまうので全ての設定が (stty(1)によると) "正常(sane)" になる。
3287 変数
3288 .I stty_init
3289 が定義されていると、stty の引数の形式を解釈できるので、より詳細な設定を
3290 行なえる。例えば、
3291 "set stty_init raw"
3292 は、以降 spawn されたプロセスの端末を raw モードで開始する。
3293 .B \-nottycopy
3294 は、ユーザーの tty に基づいた初期化を飛ばす。
3295 .B \-nottyinit
3296 は、"正常な"初期化を飛ばす。
3297 .IP
3298 .\"O Normally,
3299 .\"O .B spawn
3300 .\"O takes little time to execute.  If you notice spawn taking a
3301 .\"O significant amount of time, it is probably encountering ptys that are
3302 .\"O wedged.  A number of tests are run on ptys to avoid entanglements with
3303 .\"O errant processes.  (These take 10 seconds per wedged pty.)  Running
3304 .\"O Expect with the
3305 .\"O .B \-d
3306 .\"O option will show if
3307 .\"O .B Expect
3308 .\"O is encountering many ptys in odd states.  If you cannot kill
3309 .\"O the processes to which these ptys are attached, your only recourse may
3310 .\"O be to reboot.
3311 普通、
3312 .B spawn
3313 は、実行するのにわずかの時間しかかからない。spawn に時間をかけたいので
3314 あれば、おそらく割り込まれた pty に遭遇するだろう。たくさんのテストが
3315 間違ったプロセスに掛かり合うことを避けることができる。
3316 (割り込まれた pty につき、10 秒かかる。)
3317 .B \-d
3318 オプションをつけて Expect を走らせると、
3319 .B Expect
3320 がおかしな状態のたくさんの pty に遭遇しているかどうかが表示される。
3321 これらの pty がつながっているためにプロセスを殺せない場合、リブートするしか
3322 頼れる復旧手段はない。
3323
3324 .\"O If
3325 .\"O .I program
3326 .\"O cannot be spawned successfully because exec(2) fails (e.g. when
3327 .\"O .I program
3328 .\"O doesn't exist), an error message will be returned by the next
3329 .\"O .B interact
3330 .\"O or
3331 .\"O .B expect
3332 .\"O command as if
3333 .\"O .I program
3334 .\"O had run and produced the error message as output.
3335 .\"O This behavior is a natural consequence of the implementation of
3336 .\"O .BR spawn .
3337 .\"O Internally, spawn forks, after which the spawned process has no
3338 .\"O way to communicate with the original
3339 .\"O .B Expect
3340 .\"O process except by communication
3341 .\"O via the spawn_id.
3342 exec(2)が失敗して
3343 .I program
3344 が spawn に成功しなかった場合
3345 (例えば、
3346 .I program
3347 がなかった場合など)、エラーメッセージが次の
3348 .B interact
3349
3350 .B expect
3351 コマンドで復帰する。つまり。
3352 .I program
3353 が、出力としてエラーメッセージを出しているように見せる。
3354 この動作は、
3355 .BR spawn
3356 の実装の自然な帰結である。内部で、spawn がフォークされ、その後、
3357 spawn されたプロセスがオリジナルの
3358 .B Expect
3359 プロセスとその spawn_id で会話を行なう。
3360
3361 .\"O The
3362 .\"O .B \-open
3363 .\"O flag causes the next argument to be interpreted as a Tcl file identifier
3364 .\"O (i.e., returned by
3365 .\"O .BR open .)
3366 .\"O The spawn id can then be used as if it were a spawned process.  (The file
3367 .\"O identifier should no longer be used.)
3368 .\"O This lets you treat raw devices, files, and
3369 .\"O pipelines as spawned processes without using a pty.  0 is returned to
3370 .\"O indicate there is no associated process.  When the connection to
3371 .\"O the spawned process is closed, so is the Tcl file identifier.
3372 .\"O The
3373 .\"O .B \-leaveopen
3374 .\"O flag is similar to
3375 .\"O .B \-open
3376 .\"O except that
3377 .\"O .B \-leaveopen
3378 .\"O causes the file identifier to be left open even after the spawn id is closed.
3379 .\"O 
3380 .\"O The
3381 .\"O .B \-pty
3382 .\"O flag causes a pty to be opened but no process spawned.  0 is returned
3383 .\"O to indicate there is no associated process.  Spawn_id is set as usual.
3384 .\"O 
3385 .\"O The variable
3386 .\"O .I spawn_out(slave,fd)
3387 .\"O is set to a file identifier corresponding to the pty slave.
3388 .\"O It can be closed using "close -slave".
3389 .\"O 
3390 .\"O The
3391 .\"O .B \-ignore
3392 .\"O flag names a signal to be ignored in the spawned process.
3393 .\"O Otherwise, signals get the default behavior.
3394 .\"O Signals are named as in the
3395 .\"O .B trap
3396 .\"O command, except that each signal requires a separate flag.
3397 .B \-open
3398 フラグは、次の引数を Tcl ファイル識別子として解釈する(つまり、
3399 .BR open
3400 を行なって復帰する。
3401 )
3402 spawn id は、spawn された id として使われる。(ファイル識別子は、
3403 もう使うべきではない。) これにより、
3404 pty を除く、raw デバイス、ファイル、パイプラインを使うことができる。
3405 0 が返ってくるのは、関連するプロセスがなかった時である。
3406 spawn されたプロセスへの接続がクローズされると、Tcl ファイル識別子も
3407 クローズされる。
3408 .B \-leaveopen
3409 フラグは、
3410 .B \-open
3411 と似た動きをするが、
3412 spawn id をクローズした後もファイル識別子を開いたままにする点が違う。
3413
3414 .B \-pty
3415 フラグは、
3416 pty をオープンするがプロセスをspawnしない。0 が復帰するのは、
3417 関連するプロセスがない場合である。spawn_id は、通常通り設定される。
3418
3419 変数
3420 .I spawn_out(slave,fd)
3421 には、pty スレーブとつながっているファイル識別子が設定される。
3422 "close -slave" で close できる。
3423
3424 .B \-ignore
3425 フラグは、spawn されたプロセス中で無視されるシグナルの名前を指示する。
3426 なければ、シグナルはデフォルトの振舞いをする。シグナルの名前は
3427 .B trap
3428 コマンドで使う名前と同じである。各シグナルを分離するのにフラグが
3429 必要な点を除いては。
3430 .TP
3431 .BI strace " level"
3432 は、以降の命令を実行する前に表示を行なう。
3433 (Tcl の trace は、変数のトレースを行なう。)
3434 .I level
3435 は、トレースへの呼び出しスタックの深さを示す。
3436 .\"O the following command runs
3437 .\"O .B Expect
3438 .\"O while tracing the first 4 levels of calls,
3439 .\"O but none below that.
3440 例えば、
3441 以下のコマンドは
3442 .B Expect
3443 最初の 4 レベルの呼び出しをトレースする。
3444 それ以上の深さはトレースしない。
3445 .nf
3446
3447     expect \-c "strace 4" script.exp
3448
3449 .fi
3450 .\"O The
3451 .\"O .B -info
3452 .\"O flag causes strace to return a description of the
3453 .\"O most recent non-info arguments given.
3454
3455 .B -info
3456 フラグを指定すると、strace は最後の info でない指定の内容を復帰する。
3457 .TP
3458 .BI stty " args"
3459 .\"O is requested and the controlling terminal is accessed, the previous
3460 .\"O status of the raw and echo attributes are returned in a form which can
3461 .\"O later be used by the command.
3462 .\"O 
3463 .\"O For example, the arguments
3464 .\"O .B raw
3465 .\"O or
3466 .\"O .B \-cooked
3467 .\"O put the terminal into raw mode.
3468 .\"O The arguments
3469 .\"O .B \-raw
3470 .\"O or
3471 .\"O .B cooked
3472 .\"O put the terminal into cooked mode.
3473 .\"O The arguments
3474 .\"O .B echo
3475 .\"O and
3476 .\"O .B \-echo
3477 .\"O put the terminal into echo and noecho mode respectively.
3478 は端末モードを変更する。外部の stty コマンドと似たようなものである。
3479
3480 デフォルトでは、制御している端末がアクセスされる。他の端末は、
3481 "< /dev/tty..." を追加することでアクセスできる。(引数を一つの引数に
3482 まとめるべきではない。)
3483
3484 ステータス要求はコマンドの結果としてステータスを復帰する。
3485 ステータスが要求されずに制御している端末にアクセスする場合、直前の raw と
3486 echo の状態を返す。
3487
3488 例えば、引数
3489 .B raw
3490
3491 .B \-cooked
3492 は、端末を raw モードに設定する。
3493 引数
3494 .B \-raw
3495
3496 .B cooked
3497 は、端末を cooked モードに設定する。
3498 引数
3499 .B echo
3500
3501 .B \-echo
3502 は、端末をそれぞれ echo あるいは noecho モードに設定する。
3503 .IP
3504 .\"O The following example illustrates how to temporarily disable echoing.
3505 .\"O This could be used in otherwise-automatic
3506 .\"O scripts to avoid embedding passwords in them.
3507 .\"O (See more discussion on this under EXPECT HINTS below.)
3508 以下の例は、一時的なエコー禁止をどうやっておこなうかを示す。
3509 これは、他の自動スクリプトで、その中にパスワードが埋め込まれるのを
3510 防ぐことに使われる。(もっと議論したければ、下の EXPECT ヒントに
3511 ある。)
3512 .nf
3513
3514     stty \-echo
3515     send_user "Password: "
3516     expect_user -re "(.*)\\n"
3517     set password $expect_out(1,string)
3518     stty echo
3519
3520 .fi
3521 .TP
3522 .BI system " args"
3523 .\"O gives
3524 .\"O .I args
3525 .\"O to sh(1) as input,
3526 .\"O just as if it had been typed as a command from a terminal.
3527 .\"O .B Expect
3528 .\"O waits until the shell terminates.
3529 .\"O The return status from sh is handled the same way that
3530 .\"O .B exec
3531 .\"O handles its return status.
3532 は、
3533 .I args
3534 を、sh(1)に入力する。端末からコマンドを叩くのとちょうど同じである。
3535 .B Expect
3536 は、シェルが終るのを待つ。sh からの復帰値は、
3537 .B exec
3538 がその復帰値を扱うのと同じに扱われる。
3539 .\"O .IP
3540 .\"O In contrast to
3541 .\"O .B exec
3542 .\"O which redirects stdin and stdout to the script,
3543 .\"O .B system
3544 .\"O performs no redirection
3545 .\"O (other than that indicated by the string itself).
3546 .\"O Thus, it is possible to use programs which must talk directly to /dev/tty.
3547 .\"O For the same reason, the results of
3548 .\"O .B system
3549 .\"O are not recorded in the log.
3550 .IP
3551 .B exec
3552 が、スクリプトに標準入出力をリダイレクトするのと対照的に、
3553 対照的に
3554 .B system
3555 は、リダイレクションを行なわない。(他に文字列そのものでリダイレクトを
3556 指示しない限り。) それで、/dev/tty と直接話さなければならないプログラムを
3557 使うことができる。同じ理由で、
3558 .B system
3559 の結果は、ログに記録されない。
3560 .TP
3561 .BI timestamp " [args]"
3562 .\"O returns a timestamp.
3563 .\"O With no arguments, the number of
3564 .\"O seconds since the epoch is returned.
3565 は、タイムスタンプを復帰する。
3566 引数がない場合、復帰するまでの秒数が返る。
3567
3568 .\"O The
3569 .\"O .B \-format
3570 .\"O flag introduces a string which is returned but with 
3571 .\"O substitutions made according to the
3572 .\"O POSIX rules for strftime.  For example %a is replaced by an abbreviated
3573 .\"O weekday name (i.e., Sat).  Others are:
3574 .\"O .nf
3575 .\"O     %a      abbreviated weekday name
3576 .\"O     %A      full weekday name
3577 .\"O     %b      abbreviated month name
3578 .\"O     %B      full month name
3579 .\"O     %c      date-time as in: Wed Oct  6 11:45:56 1993
3580 .\"O     %d      day of the month (01-31)
3581 .\"O     %H      hour (00-23)
3582 .\"O     %I      hour (01-12)
3583 .\"O     %j      day (001-366)
3584 .\"O     %m      month (01-12)
3585 .\"O     %M      minute (00-59)
3586 .\"O     %p      am or pm
3587 .\"O     %S      second (00-61)
3588 .\"O     %u      day (1-7, Monday is first day of week)
3589 .\"O     %U      week (00-53, first Sunday is first day of week one)
3590 .\"O     %V      week (01-53, ISO 8601 style)
3591 .\"O     %w      day (0-6)
3592 .\"O     %W      week (00-53, first Monday is first day of week one)
3593 .\"O     %x      date-time as in: Wed Oct  6 1993
3594 .\"O     %X      time as in: 23:59:59
3595 .\"O     %y      year (00-99)
3596 .\"O     %Y      year as in: 1993
3597 .\"O     %Z      timezone (or nothing if not determinable)
3598 .\"O     %%      a bare percent sign
3599 .\"O 
3600 .\"O .fi
3601 .\"O Other % specifications are undefined.  Other characters will be passed
3602 .\"O through untouched.  Only the C locale is supported.
3603 .\"O 
3604 .\"O The
3605 .\"O .B \-seconds
3606 .\"O flag introduces a number of seconds since the epoch to be used as a source
3607 .\"O from which to format.  Otherwise, the current time is used.
3608 .\"O 
3609 .\"O The
3610 .\"O .B \-gmt
3611 .\"O flag forces timestamp output to use the GMT timezone.  With no flag,
3612 .\"O the local timezone is used.
3613 .B \-format
3614 フラグは、文字列が続くが、その文字列に
3615 POSIX の strftime のルールに従って置換がかかる。
3616 例えば、 %a は曜日(すなわち、Sat)とか。他は以下の通りである。:
3617 .nf
3618     %a      略記された曜日の名前
3619     %A      略されない曜日の名前
3620     %b      略記された月の名前
3621     %B      略されない月の名前
3622     %c      次の形式で書かれた時刻: Wed Oct  6 11:45:56 1993
3623     %d      日 (01-31)
3624     %H      時 (00-23)
3625     %I      時 (01-12)
3626     %j      日 (001-366)
3627     %m      月 (01-12)
3628     %M      分 (00-59)
3629     %p      am または pm
3630     %S      秒 (00-61)
3631     %u      日 (1-7, 月曜日が週の最初の日)
3632     %U      週 (00-53, 最初の日曜日が第1週の最初の日)
3633     %V      週 (01-53, ISO 8601 スタイル)
3634     %w      日 (0-6)
3635     %W      週 (00-53, 最初の月曜日が第1週の最初の日)
3636     %x      date-time as in: Wed Oct  6 1993
3637     %X      time as in: 23:59:59
3638     %y      year (00-99)
3639     %Y      year as in: 1993
3640     %Z      timezone (or nothing if not determinable)
3641     %%      a bare percent sign
3642
3643 .fi
3644 この他の % 指定は定義されていない。他の文字は変更されない。
3645 C ロカールだけがサポートされる。
3646
3647 .B \-seconds
3648 フラグは、
3649 タイムスタンプを秒で表す。
3650
3651 .B \-gmt
3652 GMT タイムゾーンで出力する。デフォルトはローカルタイムゾーンである。
3653 .TP
3654 .BI trap " [[command] signals]"
3655 .\"O causes the given 
3656 .\"O .I command
3657 .\"O to be executed upon future receipt of any of the given signals.
3658 .\"O The command is executed in the global scope.
3659 .\"O If
3660 .\"O .I command
3661 .\"O is absent, the signal action is returned.
3662 .\"O If
3663 .\"O .I command 
3664 .\"O is the string SIG_IGN, the signals are ignored.
3665 .\"O If
3666 .\"O .I command
3667 .\"O is the string SIG_DFL, the signals are result to the system default.
3668 .\"O .I signals
3669 .\"O is either a single signal or a list of signals.  Signals may be specified
3670 .\"O numerically or symbolically as per signal(3).  The "SIG" prefix may be omitted.
3671 .\"O 
3672 .\"O With no arguments (or the argument \-number),
3673 .\"O .B trap
3674 .\"O returns the signal number of the trap command currently being executed.
3675 .\"O 
3676 .\"O The
3677 .\"O .B \-code
3678 .\"O flag uses the return code of the command in place of whatever code Tcl
3679 .\"O was about to return when the command originally started running.
3680 .\"O 
3681 .\"O The
3682 .\"O .B \-interp
3683 .\"O flag causes the command to be evaluated using the interpreter
3684 .\"O active at the time the command started running
3685 .\"O rather than when the trap was declared.
3686 .\"O 
3687 .\"O The
3688 .\"O .B \-name
3689 .\"O flag causes the
3690 .\"O .B trap
3691 .\"O command to return the signal name of the trap command currently being executed.
3692 .\"O 
3693 .\"O The
3694 .\"O .B \-max
3695 .\"O flag causes the
3696 .\"O .B trap
3697 .\"O command to return the largest signal number that can be set.
3698 .\"O 
3699 .\"O For example, the command "trap {send_user "Ouch!"} SIGINT" will print "Ouch!"
3700 .\"O each time the user presses ^C.
3701 .\"O 
3702 .\"O By default, SIGINT (which can usually be generated by pressing ^C) and 
3703 .\"O SIGTERM cause Expect to exit.  This is due to the following trap, created
3704 .\"O by default when Expect starts.
3705 .\"O .nf
3706 .\"O 
3707 .\"O     trap exit {SIGINT SIGTERM}
3708 .\"O 
3709 .\"O .fi
3710 .\"O If you use the -D flag to start the debugger, SIGINT is redefined
3711 .\"O to start the interactive debugger.  This is due to the following trap:
3712 .\"O .nf
3713 .\"O 
3714 .\"O     trap {exp_debug 1} SIGINT
3715 .\"O 
3716 .\"O .fi
3717 .\"O The debugger trap can be changed by setting the environment variable
3718 .\"O EXPECT_DEBUG_INIT to a new trap command.  
3719 .\"O 
3720 .\"O You can, of course, override both of these just by adding trap
3721 .\"O commands to your script.  In particular, if you have your own "trap
3722 .\"O exit SIGINT", this will override the debugger trap.  This is useful
3723 .\"O if you want to prevent users from getting to the debugger at all.
3724 .\"O 
3725 .\"O If you want to define your own trap on SIGINT but still trap to the
3726 .\"O debugger when it is running, use:
3727 .\"O .nf
3728 .\"O 
3729 .\"O     if ![exp_debug] {trap mystuff SIGINT}
3730 .\"O 
3731 .\"O .fi
3732 .\"O Alternatively, you can trap to the debugger using some other signal.
3733 .\"O 
3734 .\"O .B trap
3735 .\"O will not let you override the action for SIGALRM as this is used internally
3736 .\"O to
3737 .\"O .BR Expect .
3738 .\"O The disconnect command sets SIGALRM to SIG_IGN (ignore).  You can reenable
3739 .\"O this as long as you disable it during subsequent spawn commands.
3740 .\"O 
3741 .\"O See signal(3) for more info.
3742 を実行すると、以降指定された signal を受けとると指定された
3743 .I command
3744 を実行する。
3745 このコマンドは、グローバルスコープで実行される。
3746 もし、
3747 .I command
3748 が指定されなければ、シグナルアクションが復帰する。
3749 .I command
3750 が、文字列 SIG_IGN であれば、シグナルが無視される。
3751 .I command
3752 が、文字列 SIG_DFL であれば、シグナルはデフォルトの動きをする。
3753 .I signals
3754 は、シグナルが1つでも複数のシグナルのリストでも良い。シグナルは、
3755 数字とsignal(3)に記述されている文字列のどちらで指定しても良い。
3756 プレフィクスの"SIG"は、省略しても良い。
3757
3758 引数がなければ(または、引数 \-number であれば)、
3759 .B trap
3760 は、trapコマンドで横取りされているシグナル番号を復帰する。
3761
3762 .B \-code
3763 フラグはコマンドコードを返す。Tcl がコマンドを動かし始めた時に
3764 帰そうとしたコードである。
3765
3766 .B \-interp
3767 フラグは、trap が宣言された時でなくコマンドが開始された時にインタプリタに
3768 コマンドを評価させる。
3769
3770 .B \-name
3771 フラグは、
3772 .B trap
3773 コマンドに trap のかかっているシグナル名を帰す。
3774
3775 .B \-max
3776 フラグは、
3777 .B trap
3778 コマンドに設定できる最も大きなシグナル番号を帰す。
3779
3780 例えば、"trap {send_user "Ouch!"} SIGINT" は、
3781 ユーザーが ^C を押す度に "Ouch!" を表示する。
3782
3783 デフォルトでは、SIGINT(通常 ^C を押すと発生する)や
3784 SIGTERM は、Expect を exit させてしまう。これは、Expect が起動時に
3785 実行する以下の trap によって起こっている。
3786 .nf
3787
3788     trap exit {SIGINT SIGTERM}
3789
3790 .fi
3791 -Dフラグを使ってデバッガを起動するなら、SIGINT が再定義されてから対話型
3792 デバッガが起動される。これは以下の trap によって起こる。
3793 .nf
3794
3795     trap {exp_debug 1} SIGINT
3796
3797 .fi
3798 デバッガのトラップは、環境変数 EXPECT_DEBUG_INIT を設定して、新しく
3799 trap を起動することで変更できる。
3800
3801 もちろん、スクリプトにtrapコマンドを足すだけで例のトラップは両方とも
3802 上書きできる。特に、自作の "trap exit SIGINT" があるなら、これは
3803 デバッガのトラップを上書きしてしまう。ユーザーにデバッガを全く
3804 触らせないようにするのに、便利である。
3805
3806 SIGINT のトラップを独自に定義したいけれど、デバッガにも同時に割り込んで
3807 もらいたいのであれば、こう書く。:
3808 .nf
3809
3810     if ![exp_debug] {trap mystuff SIGINT}
3811
3812 .fi
3813 代わりに、別のシグナルを使ってデバッガに割り込みをかけることができる。
3814
3815 .B trap
3816 は、SIGALRM のアクションを上書きしない。
3817 .BR Expect
3818 が内部で使用しない。
3819 disconnect コマンドは、SIGALRMを SIG_IGN (ignore)に設定する。
3820 後から発行される spawn コマンドを実行している間、SIGALRM は
3821 ディスエーブル中であれば再度イネーブルにできる。
3822
3823 もっと情報が欲しい場合、signal(3) を参照すること。
3824 .TP
3825 .BI wait " [args]"
3826 .\"O delays until a spawned process (or
3827 .\"O the current process if none is named) terminates.
3828 は、spawn されたプロセス(あるいは、名前つきのプロセスがなければ現在のプロセス)
3829 が終了するのを待つ。
3830 .IP
3831 .\"O .B wait
3832 .\"O normally returns a list of four integers.
3833 .\"O The first integer is the pid of the process that was waited upon.
3834 .\"O The second integer is the corresponding spawn id.
3835 .\"O The third integer is -1 if an operating system error occurred, or 0 otherwise.
3836 .\"O If the third integer was 0, the fourth integer is the status returned by
3837 .\"O the spawned process.  If the third integer was -1, the fourth integer is
3838 .\"O the value of errno set by the operating system.  The global variable
3839 .\"O errorCode is also set.
3840 .B wait
3841 は、通常 4 つの整数のリストを帰す。
3842 最初の整数は、終了を待ち構えているプロセスの pid である。
3843 2 つめの整数は、関連する spawn id である。
3844 3 つめの整数は、オペレーティングシステムエラーがあれば -1、
3845 そうでなければ、0 である。
3846 3 つめの整数が 0 であれば、4 つめの整数はspawnされたプロセスからのリターン
3847 コードである。3 つめの整数が -1 であれば、4 つめの整数はオペレーティングシステム
3848 によって設定された errno の値である。グローバル変数 errorCode も設定される。
3849
3850 .\"O Additional elements may appear at the end of the return value from
3851 .\"O .BR wait .
3852 .\"O An optional fifth element identifies a class of information.
3853 .\"O Currently, the only possible value for this element is CHILDKILLED in
3854 .\"O which case the next two values are the C-style signal name and a short
3855 .\"O textual description.
3856 追加の要素が
3857 .BR wait
3858 の復帰値に加わっても構わない。オプションの5つめの要素は、情報クラスの
3859 識別子である。今のところ、この要素の唯一可能な値は CHILDKILLED で、
3860 その場合、次の二つの値が C スタイルのシグナル名と短い文書による記述である。
3861 .IP
3862 .\"O The
3863 .\"O .B \-i
3864 .\"O flag declares the process to wait corresponding to the named spawn_id
3865 .\"O (NOT the process id).
3866 .\"O Inside a SIGCHLD handler,
3867 .\"O it is possible to wait for any spawned process by using the spawn id -1.
3868 .\"O 
3869 .\"O The
3870 .\"O .B \-nowait
3871 .\"O flag causes the wait to return immediately with the indication of a
3872 .\"O successful wait.  When the process exits (later), it will automatically
3873 .\"O disappear without the need for an explicit wait.
3874 .B \-i
3875 フラグによって、wait を行なう名前付き spawn_id(プロセス ID ではなく)を
3876 指定する。SIGCHLD ハンドラの内部では、spawn ID -1 を指定することで、
3877 spawn されたプロセスのいずれかを wait できる。
3878
3879 .B \-nowait
3880 フラグを指定すると、wait が成功の復帰値で即時復帰する。
3881 (あとで)そのプロセスが exit すると、自動的に後始末が行なわれ、明示的に
3882 wait する必要がない。
3883
3884 .\"O The
3885 .\"O .B wait
3886 .\"O command may also be used wait for a forked process using the arguments
3887 .\"O "-i -1".  Unlike its use with spawned processes, this command can be
3888 .\"O executed at any time.  There is no control over which process is
3889 .\"O reaped.  However, the return value can be checked for the process id.
3890 .B wait
3891 コマンドは、引数に "-i -1" を指定することによって、
3892 fork したプロセスを待つためにも使われる。
3893 spawn したプロセスに用いられる場合と異なり、
3894 このコマンドはいつでも実行できる。
3895 どのプロセスを待つかを制御することは出来ないが、
3896 返り値はプロセス ID としてチェックできる。
3897
3898 .\"O .SH LIBRARIES
3899 .SH ライブラリ
3900 .\"O Expect automatically knows about two built-in libraries for Expect scripts.
3901 .\"O These are defined by the directories named in the variables
3902 .\"O exp_library and exp_exec_library.  Both are meant to contain utility
3903 .\"O files that can be used by other scripts.
3904 .\"O 
3905 .\"O exp_library contains architecture-independent files.  exp_exec_library
3906 .\"O contains architecture-dependent files.  Depending on your system, both
3907 .\"O directories may be totally empty.  The existence of the file
3908 .\"O $exp_exec_library/cat-buffers describes whether your /bin/cat buffers
3909 .\"O by default.
3910 .\"O
3911 Expect は、スクリプトのための二つのビルトインライブラリを自動的に理解する。
3912 それらは変数 exp_library と変数 exp_exec_library に設定されたディレクトリ名と
3913 して定義される。これらのディレクトリには、他のスクリプトによって使える
3914 ユーティリティファイルが入っている。
3915
3916 exp_library には、アーキテクチャに依存しないファイルが格納される。
3917 exp_exec_library には、アーキテクチャに依存するファイルが格納される。
3918 あなたのシステムによっては、両方のディレクトリが空という場合もあり得る。
3919 ファイル $exp_exec_library/cat-buffers の存在は、あなたのシステムの
3920 /bin/cat がデフォルトでバッファリングされているかどうかに左右される。
3921
3922 .\"O .SH PRETTY-PRINTING
3923 .SH 整形印刷
3924 .\"O A vgrind definition is available for pretty-printing
3925 .\"O .B Expect
3926 .\"O scripts.
3927 .\"O Assuming the vgrind definition supplied with the
3928 .\"O .B Expect
3929 .\"O distribution is
3930 .\"O correctly installed, you can use it as:
3931 .\"O .nf
3932 .\"O 
3933 .\"O     vgrind \-lexpect file
3934 .\"O 
3935 .\"O .fi
3936 .\"O
3937 .B Expect
3938 スクリプトをきれいに印刷するための vgrind の定義がある。
3939 .B Expect
3940 ディストリビューションと一緒に配布されている vgrind 定義が正しく
3941 インストールされていると仮定して、こうすれば使える。
3942 .nf
3943
3944     vgrind \-lexpect file
3945
3946 .fi
3947
3948 .\"O .SH EXAMPLES
3949 .SH 例
3950 .\"O It many not be apparent how to put everything together that the man page
3951 .\"O describes.  I encourage you to read and try out the examples in
3952 .\"O the example directory of the
3953 .\"O .B Expect
3954 .\"O distribution.
3955 .\"O Some of them are real programs.  Others are simply illustrative
3956 .\"O of certain techniques, and of course, a couple are just quick hacks.
3957 .\"O The INSTALL file has a quick overview of these programs.
3958 マニュアルページによる記述では、あらゆるものをどう組み合わせるのかと
3959 いうことが明白ではない。私としては、
3960 .B Expect
3961 ディストリビューションの
3962 example ディレクトリにある例を読んで試してみて欲しいと思う。
3963 いくつかは本物のプログラムである。それ以外は特定のテクニックの単純な解説、
3964 あと、もちろん、単なるクイックハックが少しある。
3965 INSTALL ファイルにはこれらのプログラムの簡単な梗概が書かれている。
3966 .PP
3967 .\"O The
3968 .\"O .B Expect
3969 .\"O papers (see SEE ALSO) are also useful.  While some papers
3970 .\"O use syntax corresponding to earlier versions of Expect, the accompanying
3971 .\"O rationales are still valid and go into a lot more detail than this
3972 .\"O man page.
3973 .B Expect
3974 の論文も役に立つ(関連項目参照)。いくつかは、初期バージョンの Expect の
3975 文法を使っているが、それとともにある根本的な考えは、なお有効であり、
3976 このマニュアルページより詳細に書かれている。
3977
3978 .\"O .SH CAVEATS
3979 .SH 警告
3980 .\"O Extensions may collide with Expect's command names.  For example, 
3981 .\"O .B send
3982 .\"O is defined by Tk for an entirely different purpose.
3983 .\"O For this reason, most of the
3984 .\"O .B Expect
3985 .\"O commands are also available as "exp_XXXX".
3986 .\"O Commands and variables beginning with "exp", "inter", "spawn",
3987 .\"O and "timeout" do not have aliases.
3988 .\"O Use the extended command names if you need this compatibility between environments.
3989 .\"O 
3990 .\"O .B Expect
3991 .\"O takes a rather liberal view of scoping.
3992 .\"O In particular, variables read by commands specific to the
3993 .\"O .B Expect
3994 .\"O program will be sought first from the local scope, and if not found, in the
3995 .\"O global scope.  For example, this
3996 .\"O obviates the need to place "global timeout" in every
3997 .\"O procedure you write that uses
3998 .\"O .BR expect .
3999 .\"O On the other hand, variables written are always in the local scope (unless
4000 .\"O a "global" command has been issued).  The most common problem this causes
4001 .\"O is when spawn is executed in a procedure.  Outside the procedure, 
4002 .\"O .I spawn_id
4003 .\"O no longer exists, so the spawned process is no longer accessible
4004 .\"O simply because of scoping.  Add a "global spawn_id" to such a procedure.
4005 .\"O 
4006 .\"O If you cannot enable the multispawning capability
4007 .\"O (i.e., your system supports neither select (BSD *.*), poll (SVR>2),
4008 .\"O nor something equivalent),
4009 .\"O .B Expect
4010 .\"O will only be able to control a single process at a time.
4011 .\"O In this case, do not attempt to set
4012 .\"O .IR spawn_id ,
4013 .\"O nor should you execute processes via exec while a spawned process
4014 .\"O is running.  Furthermore, you will not be able to
4015 .\"O .B expect
4016 .\"O from multiple processes (including the user as one) at the same time.
4017 .\"O 
4018 .\"O Terminal parameters can have a big effect on scripts.  For example, if
4019 .\"O a script is written to look for echoing, it will misbehave if echoing
4020 .\"O is turned off.  For this reason, Expect forces sane terminal
4021 .\"O parameters by default.  Unfortunately, this can make things unpleasant
4022 .\"O for other programs.  As an example, the emacs shell wants to change
4023 .\"O the "usual" mappings: newlines get mapped to newlines instead of
4024 .\"O carriage-return newlines, and echoing is disabled.  This allows one to
4025 .\"O use emacs to edit the input line.  Unfortunately, Expect cannot
4026 .\"O possibly guess this.
4027 .\"O 
4028 .\"O You can request that Expect not override its default setting of
4029 .\"O terminal parameters, but you must then be very careful when writing
4030 .\"O scripts for such environments.  In the case of emacs, avoid depending
4031 .\"O upon things like echoing and end-of-line mappings.
4032 .\"O 
4033 拡張は Expect のコマンド名と衝突するかもしれない。例えば、
4034 .B send
4035 は、Tk では全く別の目的で定義されている。
4036 そういう理由で、ほとんどの
4037 .B Expect
4038 コマンドは、"exp_XXXX" という 別の記法(エイリアス)もサポートする。
4039 "exp", "inter", "spawn", "timeout" で始まるコマンドと変数は、
4040 エイリアスを持たない。
4041 この環境間の互換性が必要であれば、拡張されたコマンド名を用いること。
4042
4043 .B Expect
4044 は、かなり自由なスコープを持っている。特に、
4045 .B Expect
4046 プログラムで指定したコマンドにより読み込ませる変数は、そのローカルスコープ
4047 内でまず探索され、見つからなければ、グローバルスコープで探索される。
4048 例えば、こうすることで
4049 .BR expect
4050 を使う全てのプロシジャに "global timeout" を書く必要が
4051 なくなる。
4052 逆に、プロシジャ内に書かれた変数は全てローカルスコープ内に設定される。
4053 ("global"コマンドを指定しない限りは)。この動作が引き起こすもっとも共通した
4054 問題は、spawn がプロシジャ内で実行された時である。プロシジャの外では、
4055 .I spawn_id
4056 はスコープのため、もはや存在しないので spawn されたプロセスは単純には
4057 アクセス不能となる。そのようなプロセスには、"global spawn_id"を
4058 付け加えねばならない。
4059
4060 multi-spawn 機能が使えない(つまり、あなたのシステムが
4061 select (BSD *.*), poll (SVR>2),または、それと等価なもの のいずれも
4062 サポートしていない)場合、
4063 .B Expect
4064 は、同時に 1 プロセスしか制御できない。
4065 この場合、
4066 .IR spawn_id
4067 を無理に設定したり、spawn されたプロセスが走っている間に exec を使って
4068 プロセスを実行したりしてはならない。さらに、複数のプロセス(片方が
4069 ユーザーでも)から同時に
4070 .B expect
4071 することもできない。
4072
4073 端末制御パラメタは、スクリプトに大きな影響を与える。例えば、
4074 スクリプトがエコーを探すように書かれていれば、エコーをオフにすると
4075 動作がおかしくなる。この理由で、Expect はデフォルトで 正気の
4076 端末パラメタを設定する。不幸なことに、この設定が他のプログラムではまずい
4077 場合がある。例えば、emacs シェルは"通常の"マッピングを変更しようとする。
4078 : newlinesは、carriage-return newlines に変換されず newlines にマップされる。
4079 そして、エコーは行なわれない。こうマップされることで、emacs は入力行を
4080 編集できる。残念ながら、Expect はこのマッピングを検出できない。
4081
4082 Expect が端末パラメタのデフォルト設定を上書きしないように指定することが
4083 できるが、そういった環境で動かすスクリプトを書くときは細心の注意が
4084 必要である。emacs の場合、エコーや改行コードのマッピングを回避しなければ
4085 ならない。
4086
4087 .\"O The commands that accepted arguments braced into a single list (the
4088 .\"O .B expect
4089 .\"O variants and
4090 .\"O .BR interact )
4091 .\"O use a heuristic to decide if the list is actually one argument or
4092 .\"O many.  The heuristic can fail only in the case when the list actually
4093 .\"O does represent a single argument which has multiple embedded \\n's
4094 .\"O with non-whitespace characters between them.  This seems sufficiently
4095 .\"O improbable, however the argument "\-nobrace" can be used to force a
4096 .\"O single argument to be handled as a single argument.  This could
4097 .\"O conceivably be used with machine-generated Expect code.  Similarly,
4098 .\"O -brace forces a single argument to be handle as multiple patterns/actions.
4099 (
4100 .B expect
4101 とその変種、および、
4102 .BR interact
4103 といった)1 つのリストにブレースされた引数を受けとるコマンドは、
4104 リストが引数をどれだけ持っているのかを判断するのに、発見的手法を用いる。
4105 その発見的手法はが失敗する唯一の場合は、引数の一つに複数の\\nが埋め込まれ、
4106 その間にホワイトスペースがない場合である。これは十分検出不能な状態だが、
4107 引数"\-nobrace" で、強制的に一つの引数として扱うことができる。
4108 自動的に生成された Expect コード中で使われるかもしれない。
4109 同様に、-brace は複数のパターン/アクションをひとつの引数として扱うことを
4110 強制する。
4111
4112 .\"O .SH BUGS
4113 .SH バグ
4114 .\"O It was really tempting to name the program "sex" (for either "Smart EXec"
4115 .\"O or "Send-EXpect"), but good sense (or perhaps just Puritanism) prevailed.
4116 プログラムに "sex" ("Smart EXec" か "Send-EXpect" の略) という名前を
4117 つけるのは実に魅力的だったのだが、センスの良い方(あるいは、
4118 単にピューリタニズム)が優先された。
4119
4120 .\"O On some systems, when a shell is spawned, it complains about not being
4121 .\"O able to access the tty but runs anyway.  This means your system has a
4122 .\"O mechanism for gaining the controlling tty that
4123 .\"O .B Expect
4124 .\"O doesn't know about.  Please find out what it is, and send this information
4125 .\"O back to me.
4126 シェルが spawn されるとttyにアクセスできないと文句をいって、しかし、動作はする
4127 というシステムがある。これは、このシステムがtty制御を得るための機構を
4128 持っているが
4129 .B Expect
4130 はそれを知らないという意味である。どういう仕組みか調べて、その情報を私に
4131 知らせてほしい。
4132
4133 .\"O Ultrix 4.1 (at least the latest versions around here) considers
4134 .\"O timeouts of above 1000000 to be equivalent to 0.
4135 .\"O 
4136 .\"O Digital UNIX 4.0A (and probably other versions) refuses to allocate
4137 .\"O ptys if you define a SIGCHLD handler.  See grantpt page for more info.
4138 .\"O 
4139 .\"O IRIX 6.0 does not handle pty permissions correctly so that if Expect
4140 .\"O attempts to allocate a pty previously used by someone else, it fails.
4141 .\"O Upgrade to IRIX 6.1.
4142 Ultrix 4.1 (少なくとも最新バージョンのあたり) では、
4143 1000000 を超えるタイムアウトを 0 とみなしてしまう。
4144
4145 Digital UNIX 4.0A (おそらく他のバージョンも)は SIGCHLD ハンドラを
4146 定義すると、pty の割り付けを拒否する。詳細は grantpt ページを参照のこと。
4147
4148 IRIX 6.0 は、pty へのアクセス制御を正確に扱えない。それで、
4149 Expect は、pty がアロケートできない場合は、他の人が前に使った pty の
4150 アロケートを試みる。
4151 IRIX 6.1 にアップグレードすること。
4152
4153 .\"O Telnet (verified only under SunOS 4.1.2) hangs if TERM is not set.
4154 .\"O This is a problem under cron, at and in cgi scripts, which do not
4155 .\"O define TERM.  Thus, you must set it explicitly - to what type is
4156 .\"O usually irrelevant.  It just has to be set to something!  The
4157 .\"O following probably suffices for most cases.
4158 telnet (SunOS 4.1.2 でのみ確認)は、TERM が設定されてないと
4159 ハングする。この問題は cron や at や CGI スクリプトで使う時に問題だ
4160 (設定しないので)。それで、
4161 明示的に指定しなくてはならない - 本当のタイプは通常関係ない。
4162 何かに設定してないと駄目なのだ! 以下の記述はおそらくほとんどの場合を
4163 満足させるだろう。
4164 .nf
4165
4166     set env(TERM) vt100
4167
4168 .fi
4169
4170 .\"O Tip (verified only under BSDI BSD/OS 3.1 i386) hangs if SHELL and HOME
4171 .\"O are not set.  This is a problem under cron, at and in cgi scripts,
4172 .\"O which do not define these environment variables.  Thus, you must set
4173 .\"O them explicitly - to what type is usually irrelevant.  It just has to
4174 .\"O be set to something!  The following probably suffices for most cases.
4175 tipt (BSDI BSD/OS 3.1 i386 でのみ確認)は、SHELL と HOME が設定されてないと
4176 ハングする。この問題は cron や at や CGI スクリプトで使う時に問題だ
4177 (設定しないので)。それで、
4178 明示的に指定しなくてはならない - 本当のタイプは通常関係ない。
4179 何かに設定してないと駄目なのだ! 以下の記述はおそらくほとんどの場合を
4180 満足させるだろう。
4181 .nf
4182
4183     set env(SHELL) /bin/sh
4184     set env(HOME) /usr/local/bin
4185
4186 .fi
4187
4188
4189 .\"O Some implementations of ptys are designed so that the kernel throws
4190 .\"O away any unread output after 10 to 15 seconds (actual number is
4191 .\"O implementation-dependent) after the process has closed the file
4192 .\"O descriptor.  Thus
4193 .\"O .B Expect
4194 .\"O programs such as
4195 .\"O .nf
4196 .\"O 
4197 .\"O     spawn date
4198 .\"O     sleep 20
4199 .\"O     expect
4200 .\"O 
4201 .\"O .fi
4202 .\"O will fail.  To avoid this, invoke non-interactive programs with
4203 .\"O .B exec
4204 .\"O rather than
4205 .\"O .BR spawn .
4206 .\"O While such situations are conceivable, in practice I have never
4207 .\"O encountered a situation in which the final output of a truly
4208 .\"O interactive program would be lost due to this behavior.
4209 .\"O 
4210 .\"O On the other hand, Cray UNICOS ptys throw away any unread output
4211 .\"O immediately after the process has closed the file descriptor.  I have
4212 .\"O reported this to Cray and they are working on a fix.
4213 .\"O 
4214 .\"O Sometimes a delay is required between a prompt and a response, such as
4215 .\"O when a tty interface is changing UART settings or matching baud rates
4216 .\"O by looking for start/stop bits.  Usually, all this is require is to
4217 .\"O sleep for a second or two.  A more robust technique is to retry until
4218 .\"O the hardware is ready to receive input.  The following example uses
4219 .\"O both strategies:
4220 .\"O .nf
4221 .\"O 
4222 .\"O     send "speed 9600\\r";
4223 .\"O     sleep 1
4224 .\"O     expect {
4225 .\"O         timeout {send "\\r"; exp_continue}
4226 .\"O         $prompt
4227 .\"O     }
4228 .\"O 
4229 .\"O .fi
4230 .\"O
4231 pty のインプリメントの中には、プロセスがファイル記述子をクローズした後、
4232 読んでない出力を 10 から 15 秒後(この値はインプリメントに依存)に投げてくる
4233 ものがある。それゆえ、
4234 .nf
4235
4236     spawn date
4237     sleep 20
4238     expect
4239
4240 .fi
4241 のような
4242 .B Expect
4243 プログラムは失敗する。失敗しないように非対話的なプログラムでは
4244 .BR spawn
4245 せずに
4246 .B exec
4247 すること。こういう状況は考えられるが、実際には私はまだその状態に
4248 陥ったことがない。つまり、この原因で対話プログラムの最後の出力を
4249 取りこぼすという状態になったことがない。
4250
4251 一方、Cray UNICOS の pty は読み込んでいない出力をファイルディスクリプタを
4252 プロセスが閉じるとすぐに投げてくる。私は Cray にこの動きについて報告し、
4253 回避するための修正を行なった。
4254
4255 プロンプトと応答の間にディレイが必要な場合がある。tty インターフェースが
4256 UART の設定を変えたり、スタート/ストップビットを探してボーレートを合わせて
4257 いる時などである。通常、ここで必要とされているものは 1 秒か 2 秒の待ち合わせである。
4258 もっとしっかりしたやり方はハードウェアが入力を受ける準備ができるまで繰り返す
4259 ことである。以下の例は、両方の戦略を採用している。:
4260 .nf
4261
4262     send "speed 9600\\r";
4263     sleep 1
4264     expect {
4265         timeout {send "\\r"; exp_continue}
4266         $prompt
4267     }
4268
4269 .fi
4270
4271 .\"O trap \-code will not work with any command that sits in Tcl's event
4272 .\"O loop, such as sleep.  The problem is that in the event loop, Tcl
4273 .\"O discards the return codes from async event handlers.  A workaround is
4274 .\"O to set a flag in the trap code.  Then check the flag immediately after
4275 .\"O the command (i.e., sleep).
4276 \-code をトラップするのは Tcl のイベントループに依存しているコマンド
4277 (sleep など)では動かない。
4278 問題は、イベントループの中では Tcl は非同期イベントハンドラからの
4279 返り値を捨てているからである。
4280 回避方法としては、トラップコードでフラグをセットし、
4281 コマンド(sleep など)の直後でフラグをチェックすることである。
4282
4283 .\"O .SH EXPECT HINTS
4284 .SH EXPECT ヒント
4285 .\"O There are a couple of things about
4286 .\"O .B Expect
4287 .\"O that may be non-intuitive.
4288 .\"O This section attempts to address some of these things with a couple of
4289 .\"O suggestions.
4290 .\"O 
4291 .\"O A common expect problem is how to recognize shell prompts.  Since
4292 .\"O these are customized differently by differently people and different
4293 .\"O shells, portably automating rlogin can be difficult without knowing
4294 .\"O the prompt.  A reasonable convention is to have users store a regular
4295 .\"O expression describing their prompt (in particular, the end of it) in
4296 .\"O the environment variable EXPECT_PROMPT.  Code like the following
4297 .\"O can be used.  If EXPECT_PROMPT doesn't exist, the code still has a good chance of functioning correctly.
4298 .\"O .nf
4299 .\"O 
4300 .\"O     set prompt "(%|#|\\\\$) $"          ;# default prompt
4301 .\"O     catch {set prompt $env(EXPECT_PROMPT)}
4302 .\"O 
4303 .\"O     expect -re $prompt
4304 .\"O 
4305 .\"O .fi
4306 .\"O I encourage you to write
4307 .\"O .B expect
4308 .\"O patterns that include the end of whatever
4309 .\"O you expect to see.  This avoids the possibility of answering a question
4310 .\"O before seeing the entire thing.  In addition, while you may well be
4311 .\"O able to answer questions before seeing them entirely, if you answer
4312 .\"O early,  your answer may appear echoed back in the middle of the question.
4313 .\"O In other words, the resulting dialogue will be correct but look scrambled.
4314 .\"O 
4315 .\"O Most prompts include a space character at the end.
4316 .\"O For example, the prompt from ftp is 'f', 't', 'p', '>' and <blank>.
4317 .\"O To match this prompt, you must account for each of these characters.
4318 .\"O It is a common mistake not to include the blank.
4319 .\"O Put the blank in explicitly.
4320 .\"O 
4321 .\"O If you use a pattern of the form X*, the * will match all the output
4322 .\"O received from the end of X to the last thing received.
4323 .\"O This sounds intuitive but can be somewhat confusing because the phrase
4324 .\"O "last thing received" can vary depending upon the speed of the computer
4325 .\"O and the processing of I/O both by the kernel and the device driver.
4326 .\"O
4327 .B Expect
4328 について、直観的でない点が少しある。
4329 このセクションではそういったことの指摘とそれに対する示唆を試みる。
4330
4331 共通の expect の問題は、シェルプロンプトを認識する方法である。
4332 その設定も、それを扱う人も、使うシェルもまちまちなので、実際に出てくる
4333 プロンプトを知らずに、汎用的に rlogin を自動化することは困難である。
4334 妥当な線は、ユーザーにプロンプトにマッチする正規表現(特にプロンプトの
4335 終りの部分)を環境変数 EXPECT_PROMPT に保存させることである。
4336 以下のようなコードでできる。
4337 EXPECT_PROMPT がなくても、コードは正しく動く可能性がある。
4338 .nf
4339
4340     set prompt "(%|#|\\\\$) $"          ;# default prompt
4341     catch {set prompt $env(EXPECT_PROMPT)}
4342
4343     expect -re $prompt
4344
4345 .fi
4346 私としては、見えると思っているものの終りの部分を含んだ
4347 .B expect
4348 パターンを書くように勧める。そうすれば、全体を見る前に応答を返してしまう
4349 ことを避けることができる。さらに、全体が見える前に答えることもできるが
4350 その文字は質問に混ざって echo される。言い替えれば、会話は正常だが見た目は
4351 混ざって見える。
4352
4353 ほとんどのプロンプトの終りの文字はスペースである。例えば、
4354 ftpからのプロンプトは、'f', 't', 'p', '>' そして <blank> である。
4355 このプロンプトにマッチさせるには、この文字の一つ一つにマッチしなければ
4356 ならない。blank を含めないのは、よくある誤りである。明示的に blank を
4357 入れるように。
4358
4359 X* の形のパターンを使うのであれば、* はXから最後に受けとる何かまでの
4360 全てにマッチする。これは一見直観的だが、"最後に受けとる何か"が
4361 コンピュータの速度とカーネルとデバイスドライバによるI/O処理によって
4362 変わってしまうので混乱するだろう。
4363 .PP
4364 .\"O In particular, humans tend to see program output arriving in huge chunks
4365 .\"O (atomically) when in reality most programs produce output one
4366 .\"O line at a time.  Assuming this is the case, the * in the pattern of the
4367 .\"O previous paragraph may only match the end of the current line even though
4368 .\"O there seems to be more, because at the time of the match that was all
4369 .\"O the output that had been received.
4370 特に、人間はプログラムの出力が巨大なひとまとまりとしてやってくると思いがち
4371 だが、実際には、ほとんどのプログラムは一行を一度に送る。
4372 こう仮定すると、直前の段落のパターンにあった * は、行の終りにしか
4373 マッチしないかも知れない。たとえ、もっと入力があると思われる場合でも
4374 出力を全て受けとった時点でしかマッチを行なわないのである。
4375 .PP
4376 .\"O .B expect
4377 .\"O has no way of knowing that further output is coming unless your
4378 .\"O pattern specifically accounts for it.
4379 .B expect
4380 は、指定したパターンが教えてくれない限り、出力がさらにやってくるのか
4381 どうかわからない。
4382 .PP
4383 .\"O Even depending on line-oriented buffering is unwise.  Not only do programs
4384 .\"O rarely make promises about the type of buffering they do, but system
4385 .\"O indigestion can break output lines up so that lines break at seemingly
4386 .\"O random places.  Thus, if you can express the last few characters
4387 .\"O of a prompt when writing patterns, it is wise to do so.
4388 .\"O 
4389 .\"O If you are waiting for a pattern in the last output of a program
4390 .\"O and the program emits something else instead, you will not be able to
4391 .\"O detect that with the
4392 .\"O .B timeout
4393 .\"O keyword.  The reason is that
4394 .\"O .B expect
4395 .\"O will not timeout \- instead it will get an
4396 .\"O .B eof
4397 .\"O indication.
4398 .\"O Use that instead.  Even better, use both.  That way if that line
4399 .\"O is ever moved around, you won't have to edit the line itself.
4400 .\"O 
4401 .\"O Newlines are usually converted to carriage return, linefeed sequences
4402 .\"O when output by the terminal driver.  Thus, if you want a pattern that
4403 .\"O explicitly matches the two lines, from, say, printf("foo\\nbar"),
4404 .\"O you should use the pattern "foo\\r\\nbar".
4405 行指向のバッファリングを行なっている場合ですら、賢いやり方とはいえない。
4406 プログラムはバッファリングのタイプをめったに保証しないだけでなく、その際に
4407 消化不良を起こして出力行を中断し、行末をバッファ中のランダムな位置に
4408 置いてしまう。
4409 それで、パターンを書く時には、プロンプトの最後の何文字かを入れておいた方が
4410 賢いやり方といえるのである。
4411
4412 プログラムの最後の出力にあるパターンを待ち、実際には何がしか他のものが
4413 発行されている場合には
4414 .B timeout
4415 キーワードで判定することができない。理由は、
4416 .B expect
4417 が、タイムアウトしない \- そのかわりに
4418 .B eof
4419 を見つけられる \-
4420 からである。
4421 代わりになるものを使うこと。もっと良いのは、両方使うことだろう。
4422 行が回り込んだ場合でも、行そのものを編集するべきではない。
4423
4424 tty ドライバによって出力される時に
4425 newline は、普通 carriage return, linefeed の組に変換される。
4426 それで、2 ラインにマッチするには、例えば、printf("foo\\nbar") に
4427 マッチさせるには、"foo\\r\\nbar" というパターンを使うことになる。
4428 .PP
4429 .\"O A similar translation occurs when reading from the user, via
4430 .\"O .BR expect_user .
4431 .\"O In this case, when you press return, it will be
4432 .\"O translated to a newline.  If
4433 .\"O .B Expect
4434 .\"O then passes that to a program
4435 .\"O which sets its terminal to raw mode (like telnet), there is going to
4436 .\"O be a problem, as the program expects a true return.  (Some programs
4437 .\"O are actually forgiving in that they will automatically translate
4438 .\"O newlines to returns, but most don't.)  Unfortunately, there is no way to find
4439 .\"O out that a program put its terminal into raw mode.
4440 似たような変換は、ユーザーから
4441 .BR expect_user
4442 を通して入力を読み込む時にも起こる。この場合、ユーザーがリターンを
4443 押すと、それは newline に変換される。その後、
4444 .B Expect
4445 が端末モードを raw モード(telnet のような)を設定すると、問題が発生する
4446 可能性がある。プログラムが本当のリターンを待ってしまうからである。(プログラムの
4447 中には、newline をリターンに変えても大丈夫なものもあるが、ほとんどはだめである。)
4448 残念ながら、プログラムが端末を raw モードにすることを検出する方法がない。
4449 .PP
4450 .\"O Rather than manually replacing newlines with returns, the solution is to
4451 .\"O use the command "stty raw", which will stop the translation.
4452 .\"O Note, however, that this means that you will no longer get the cooked
4453 .\"O line-editing features.
4454 手で newline をリターンに変えるのではなく、"stty raw"を使うのが解決策である。
4455 stty raw は、変換を停止する。しかし、こうすると cooked モードの行編集機能が
4456 使えなくなるということに注意すること。
4457 .PP
4458 .\"O .B interact
4459 .\"O implicitly sets your terminal to raw mode so this problem will not arise then.
4460 .\"O 
4461 .\"O It is often useful to store passwords (or other private information)
4462 .\"O in
4463 .\"O .B Expect
4464 .\"O scripts.  This is not recommended since anything that is
4465 .\"O stored on a computer is susceptible to being accessed by anyone.
4466 .\"O Thus, interactively prompting for passwords from a script is a smarter
4467 .\"O idea than embedding them literally.  Nonetheless, sometimes such embedding
4468 .\"O is the only possibility.
4469 .B interact
4470 は、端末を raw モードに設定するので、この問題は発生しない。
4471
4472 .B Expect
4473 スクリプトの中でパスワード(や他の機密情報)を保存すると便利なことは
4474 よくある。だれかのアクセスを受けるとその影響を受けてしまうコンピュータで
4475 そういうことをするのは勧められない。それで、パスワードのプロンプトを
4476 スクリプトから出すのが、文字通りパスワードを埋め込むよりは、良い考えと
4477 いえる。とはいうものの、そういった埋め込みをするしかない場合もある。
4478 .PP
4479 .\"O Unfortunately, the UNIX file system has no direct way of creating
4480 .\"O scripts which are executable but unreadable.  Systems which support
4481 .\"O setgid shell scripts may indirectly simulate this as follows:
4482 不幸なことに、UNIX のファイルシステムは「実行可能で読めない」スクリプトを
4483 作る直接の方法がない。setgid シェルスクリプトをサポートしたシステムでは、
4484 次のようにすることで間接的にシミュレートできる。
4485 .PP
4486 .\"O Create the
4487 .\"O .B Expect
4488 .\"O script (that contains the secret data) as usual.
4489 .\"O Make its permissions be 750 (\-rwxr\-x\-\-\-) and owned by a trusted group
4490 ,
4491 .\"O i.e., a group which is allowed to read it.  If necessary, create a new
4492 .\"O group for this purpose.  Next, create a /bin/sh script with
4493 .\"O permissions 2751 (\-rwxr\-s\-\-x) owned by the same group as before.
4494 .B Expect
4495 スクリプト(機密情報の入った)を普通に作る。
4496 そのパーミッションを 750 (\-rwxr\-x\-\-\-) に設定し、trusted group 
4497 つまり、読んでも良いグループ の所有とする。必要なら、この目的のための
4498 新しいグループをつくること。次に、/bin/sh スクリプトを パーミッション
4499  2751 (\-rwxr\-s\-\-x) で、同じグループの所有で作成する。
4500 .PP
4501 .\"O The result is a script which may be executed (and read) by anyone.
4502 .\"O When invoked, it runs the
4503 .\"O .B Expect
4504 .\"O script.
4505 こうすると、シェルスクリプトはだれからも実行でき(かつ、読め)る。
4506 実行すると、それは
4507 .B Expect
4508 スクリプトを実行する。
4509
4510 .\"O .SH SEE ALSO
4511 .SH 関連項目
4512
4513 .BR Tcl (3),
4514 .BR libexpect (3)
4515 .br
4516 .I
4517 "Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs"
4518 \fRby Don Libes, pp. 602, ISBN 1-56592-090-2, O'Reilly and Associates, 1995.
4519 .br
4520 .I
4521 "expect: Curing Those Uncontrollable Fits of Interactivity" \fRby Don Libes,
4522 Proceedings of the Summer 1990 USENIX Conference,
4523 Anaheim, California, June 11-15, 1990.
4524 .br
4525 .I
4526 "Using
4527 .B expect
4528 to Automate System Administration Tasks" \fRby Don Libes,
4529 Proceedings of the 1990 USENIX Large Installation Systems Administration
4530 Conference, Colorado Springs, Colorado, October 17-19, 1990.
4531 .br
4532 .I
4533 "Tcl: An Embeddable Command Language" \fRby John Ousterhout,
4534 Proceedings of the Winter 1990 USENIX Conference,
4535 Washington, D.C., January 22-26, 1990.
4536 .br
4537 .I
4538 "expect: Scripts for Controlling Interactive Programs" \fRby Don Libes,
4539 Computing Systems, Vol. 4, No. 2, University of California Press Journals,
4540 November 1991.
4541 .br
4542 .I
4543 "Regression Testing and Conformance Testing Interactive Programs", \fRby Don
4544 Libes, Proceedings of the Summer 1992 USENIX Conference, pp. 135-144,
4545 San Antonio, TX, June 12-15, 1992.
4546 .br
4547 .I
4548 "Kibitz \- Connecting Multiple Interactive Programs Together", \fRby Don Libes,
4549 Software \- Practice & Experience, John Wiley & Sons, West Sussex, England,
4550 Vol. 23, No. 5, May, 1993.
4551 .br
4552 .I
4553 "A Debugger for Tcl Applications", \fRby Don Libes,
4554 Proceedings of the 1993 Tcl/Tk Workshop, Berkeley, CA, June 10-11, 1993.
4555
4556 .\"O .SH AUTHOR
4557 .SH 著者
4558
4559 Don Libes, National Institute of Standards and Technology
4560
4561 .\"O .SH ACKNOWLEDGMENTS
4562 .SH 謝辞
4563 .\"O Thanks to John Ousterhout for Tcl, and Scott Paisley for inspiration.
4564 .\"O Thanks to Rob Savoye for Expect's autoconfiguration code.
4565 Tclを生み出した John Ousterhout と、インスピレーションを与えてくれた
4566 Scott Paisley に感謝する。
4567 Expect のオートコンフィギュレーションコードについて、 Rob Savoye に感謝する。
4568
4569 .PP
4570 .\"O The HISTORY file documents much of the evolution of
4571 .\"O .BR expect .
4572 .\"O It makes interesting reading and might give you further insight to this
4573 .\"O software.  Thanks to the people mentioned in it who sent me bug fixes
4574 .\"O and gave other assistance.
4575 HISTORY ファイルに
4576 .B expect
4577 の進化の大部分が記述されている。このファイルは面白く読めて、かつ、
4578 あなたのこのソフトウェアへの洞察をより深くするだろう。このファイルに
4579 書かれている、私にバグフィックスを送ってくれた人たちや、他の援助を
4580 してくれた人たちに感謝する。
4581 .PP
4582 .\"O Design and implementation of
4583 .\"O .B Expect
4584 .\"O was paid for in part by the U.S. government and is therefore in the public
4585 .\"O domain.
4586 .\"O However the author and NIST would like credit
4587 .\"O if this program and documentation or portions of them are used.
4588 .B Expect
4589 の設計と実装は、部分的にアメリカ政府からその対価をもらっているので、
4590 パブリックドメインである。しかし、このプログラムとドキュメントあるいは
4591 その一部が使われたなら、著者と NIST への謝辞を述べてもらいたい。