DragonOS/user/apps/shell/cmd_test.c
wwc-15172310230 237e95c6dd
调整user下libs的libc目录结构 (#103)
* 调整user下libs的libc目录结构

* 修正.gitignore文件的问题

* 修复无法编译的问题

Co-authored-by: longjin <longjin@RinGoTek.cn>
2022-12-11 22:22:10 +08:00

32 lines
701 B
C

#include "cmd_test.h"
#include <libc/src/stdio.h>
#include <libc/src/stdlib.h>
#include <libc/src/string.h>
#include <libc/src/unistd.h>
int shell_pipe_test(int argc, char **argv)
{
int ret = -1;
int fd[2];
pid_t pid;
char buf[512] = {0};
char *msg = "hello world";
ret = pipe(fd);
if (-1 == ret) {
printf("failed to create pipe\n");
return -1;
}
pid = fork();
if (0 == pid) {
// close(fd[0]);
ret = write(fd[1], msg, strlen(msg));
exit(0);
} else {
// close(fd[1]);
ret = read(fd[0], buf, sizeof(buf));
printf("parent read %d bytes data: %s\n", ret, buf);
}
return 0;
}