Skip to content
Advertisement

Spawn process and redirect current bash script’s output to it

How can I spawn a new background process from a bash script and redirect the current script’s stdout/stderr to that process’s stdin using fd redirection? I know of a few ways to accomplish the same effect, such as using a named pipe or a temporary file, using coprocs, or running the whole script in a subshell and redirecting the ouptut of that to the other process, but I am looking for a simple one line IO redirection from within the script, in the same way I can do this: exec 2>&1. Basically, I want to do something like this (the way the process is spawned can be changed of course):

JavaScript

Advertisement

Answer

I found a solution to this using process substitution:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement