c - How to use popen to input and output in the same time? -
this question has answer here:
i use psuedo-code express want do:
file* fd = popen("/bin/cat", ...); write data stdin of `/bin/cat` using fd; read data stdout of `/bin/cat` using fd;
is possible?
popen() can read new process. if need read , write,
- create pipe connected new process using
pipe()
. - fork new process using
fork()
- redirect process's input , outputs pipes created earlier using
dup2()
- call exec on child process (the new process) using
exec
family functions
Comments
Post a Comment