以下では、飛び蹴りに近い方法も説明するが、あまり凝ったことをするより も、次節に紹介する方法を用いた方が良い。
標準出力に出力された結果を保存するには、色々な方法がある。
oyabun% script |
| 参考までに add.c |
#include <stdio.h>
main()
{
int a, b;
printf("add two integers: ");
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
}
|
oyabun% add > add.out |
| add-tty.c |
#include <stdio.h>
main()
{
int a, b;
FILE *con;
con = fopen("/dev/tty", "w");
fprintf(con, "add two integers: ");
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
}
|
oyabun% add-tty > add.out |
oyabun% add | tee add.out |
| add-flush.c |
#include <stdio.h>
main()
{
int a, b;
printf("add two integers: "); fflush(stdout);
scanf("%d %d", &a, &b);
printf("%d\n", a+b);
}
|
oyabun% add | tee add.out |
M-x, shellリターン |
*shell* バッファーができる。この中で、普通の端末のよ
うにコマンドが実行できるが、あくまでも Emacs のバッファーであるから、
内容はファイルに自由に書き出せる。