It would be beneficial to have a device that can provide both stdin and stdout redirection for a subprocess. Look into this.
https://www.rubydoc.info/stdlib/open3/Open3.popen3 https://docs.python.org/3/library/subprocess.html https://man.openbsd.org/pipe.2
Other relevant system calls: pipe pipe2 dup2 execlp
Other relevant system calls:
pipe
pipe2
dup2
execlp