#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
/*
* 使用格式:write user
* 与终端用户的对话
*
*/
int main(int ac,char *av[]){
int fd;
char buf[50];
//参数的判断
if(ac != 2){
fprintf(stderr,"usage:write0 ttyname\n");
exit(1);
}
//打开设备文件
fd = open(av[1],O_WRONLY);
if(fd == -1){
perror(av[1]);
exit(1);
}
//循环输入数据直到终止
while(fgets(buf,50,stdin)!=NULL){
if(write(fd,buf,strlen(buf))==-1)
break;
}
close(fd);
}
Shell命令编写——write,与终端对话
最新推荐文章于 2024-06-09 00:30:27 发布