S
S
Sergey Cherepanov2013-09-16 16:29:23
linux
Sergey Cherepanov, 2013-09-16 16:29:23

Redirecting STDERR and STDOUT to different scripts on STDIN?

Hello, actually the question is in the title, I can not google it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Cherepanov, 2013-09-16
@fear86

Found a solution via overriding streams:
{ command1 2>&3 | command2; } 3>&1 1>&2 | command3
From here: stackoverflow.com/questions/9112979/pipe-stdout-and-stderr-to-two-different-processes-in-shell-script

@
@ntkt, 2013-09-16
_

You can, for example, create named pipes (google: mkfifo).
Let's make a test program test_redir.c with the following content:
#include <stdio.h>
int main()
{
fprintf(stdout,"Test STDOUT\n");
fprintf(stderr,"Test STDERR\n"); return 0;
}
Collected, prepared for launch.
$ gcc test_redir.c -o test_redir
$ chmod +x test_redir
Now let's create the pipes: Let 's run Now, in two new terminals, let's see what's in the pipes: This is a bad example, so in the first terminal, the output will appear only after we see what's in the test_err pipe, but the idea should be clear
$ mkfifo test_out
$ mkfifo test_err
.
$ ./test_redir 1>test_out 2>test_err
$ cat tmp/test_out
Test STDOUT
$ cat tmp/test_err
Test STDERR

J
jcmvbkbc, 2013-09-16
@jcmvbkbc

Only through an external fifo, like this:

D=`mktemp -d` ; mkfifo "$D/stdout" ; mkfifo "$D/stderr" ; cmd_stdout < "$D/stdout" & cmd_stderr < "$D/stderr" & cmd > "$D/stderr" 2>"$D/stdout" & wait ; rm -rf "$D"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question