stdin:输入流
stdout:输出流
strerr:错误流
#include <stdio.h>
int main()
{
//printf("please input the value a : \n");
fprintf(stdout, "please input the value a :");
int a ;
//scanf("%d", &a); fscanf的封装
fscanf(stdin, "%d", &a);
if(a<0) {
fprintf(stderr, "the value must > 0 \n");
return 1;
}
return 0;
}
./main.out > a.txt //覆盖
./main.out >> a.txt //追加
./main.out < input.txt //将input中的内容当做输入流
#1>输出流 2>错误流 <输入流
./main.out 1>stdout.txt 2>stderr.txt <input.txt
管道:传输数据流
#管道
#将ls的输出流通过管道当做grep 的输入流
[root@VM_0_8_centos les1]# ls /etc/ | grep ab
anacrontab
crontab
crypttab
fstab
inittab
mtab
rabbitmq
rwtab
rwtab.d
statetab
[root@VM_0_8_centos les1]# ps -ef | grep ssh
root 2081 1 0 Aug29 ? 00:01:36 /usr/sbin/sshd -D
root 3569 32588 0 12:30 pts/0 00:00:00 grep --color=auto ssh
root 32586 2081 0 11:41 ? 00:00:00 sshd: root@pts/0
网友评论