bash - How do I redirect/pipe all of my terminal shell script's output into another program from within the script? -


i have script want equivalent of this:

myscript | anotherprogram

but within script. don't want invoke

mysubtask | anotherprogram

each time have run subtasks in script, want filter started , out & err routed (the script not interactive).

so in end want

  1. set out & err input of anotherprogram. anotherprogram run 1 instance of script of output goes it.
  2. run rest of script normal out & err of subsequent echos , subtask outputs going anotherprogram continuously (i want anotherprogram run once, during whole rest of script)

there 2 simple ways can see achieve this. first, use subshell parentheses:

(   echo hello   echo world ) 2>&1 | anotherprogram 

or use exec redirect various file descriptors @ top of script

exec > >( anotherprogram ) # send stdout anotherprogram exec 2>&1                  # merge stderr stdout  echo hello echo world 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -