C 如何使用popen同时输入和输出?
我使用psuedo代码来表达我想要做的事情:C 如何使用popen同时输入和输出?,c,linux,unix,pipe,C,Linux,Unix,Pipe,我使用psuedo代码来表达我想要做的事情: FILE* fd = popen("/bin/cat", ...); Write some data to the stdin of `/bin/cat` using fd; Read all data from the stdout of `/bin/cat` using fd; 可能吗?popen()只能从新进程中读取。如果你需要读和写 使用pipe()创建将连接到新进程的管道 使用Fork() 将进程的输入和输出重定向到先前使用dup2()
FILE* fd = popen("/bin/cat", ...);
Write some data to the stdin of `/bin/cat` using fd;
Read all data from the stdout of `/bin/cat` using fd;
可能吗?popen()只能从新进程中读取。如果你需要读和写
- 使用
创建将连接到新进程的管道pipe()
- 使用
Fork()
- 将进程的输入和输出重定向到先前使用
dup2()创建的管道
- 使用
系列函数对子进程(新进程)调用execexec