Redirect standard error to input of other process, 2| ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect standard error to input of other process, 2| ?
# 1  
Old 06-20-2009
Redirect standard error to input of other process, 2| ?

Hello,

I would like to know if there is a shell in which operations such as 2| (redirect standard error of one process to the standard input of another one) exist?
I know it is possible to do it in bash with things like:
(process 2>&1) | other_process
but I find it a bit intricate when dealing with several processes.

Ideally having a 3| rather than a 2| would be perfect (my ultimate goal is to pipe the output of process to tee to create two copies of it, for instance on stdout and on the descriptor number 3, so that two processes may work on it at the same time).
# 2  
Old 06-20-2009
As far as I know there is no Unix or Linux shell that supports "filedescriptor|" semantics such as 2|
# 3  
Old 06-21-2009
Hi.

There is a way (of sorts)!

But it does makes some assumptions:
1. That my_process_1 and my_process_2 (see below) read only from pipes (and are happy to wait for data)
2. You control how your program writes its output (i.e. it doesn't send stdout or stderr off somewhere else

Steps:
1. Create two pipes:
mknod STDOUT.pipe p
mknod STDERR.pipe p

2. Create two processes to read from these pipes, in the background
cat STDOUT.pipe | ./my_process_1 &
cat STDERR.pipe | ./my_process_2 &

In your program, or from a separate scripts direct STDOUT and STDERR to the new pipes
exec 1> STDOUT.pipe
exec 2> STDERR.pipe
your program call (or script) goes here
# 4  
Old 06-24-2009
Thanks for the answers. I suspected that such a thing as 2| did not exist in any shell, but I thought this was the place to ask to be sure of it!

The idea of creating the pipes myself is pretty interesting. I don't acutally need to create a pipe for stdout since the regular pipe does that.
I tested the idea for counting the number of lines of a gzipped file and print the last lines by using one gunzip and piping the output to tee and two other processes:

mknod 3.pipe p
cat 3.pipe | wc -l &
zcat diff.gz | (tee /dev/fd/3 | tail -n 3) 3> 3.pipe

seems more easy to write than
zcat diff.gz | ((tee /dev/fd/3 | tail -n 3) 3>&1) | wc -l

(I'm not sure which of those parenthesis are necessary).

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Removing punctuations from file input or standard input

Just started learning Unix and received my first assignment recently. We haven't learned many commands and honestly, I'm stumped. I'd like to receive assistance/guidance/hints. 1. The problem statement, all variables and given/known data: How do I write a shell script that takes in a file or... (4 Replies)
Discussion started by: fozilla
4 Replies

2. UNIX for Dummies Questions & Answers

Redirect Standard Error to /dev/null is not working.

Hello. When I run a .ksh that contains the command below, and there is no file available in the source location the "FILE_NAME_*.CSV not found" error is still being displayed. FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null. This is interfering with the rest... (4 Replies)
Discussion started by: jimbojames
4 Replies

3. Shell Programming and Scripting

How redirect standard output to a file

Hi guys, i have a script named purgeErrors.ksh, when i execute this script i need to redirect the output to a log file in the same directory, how can i do that ?? -- Aditya (5 Replies)
Discussion started by: chaditya
5 Replies

4. UNIX for Dummies Questions & Answers

Redirect Standard output and standard error into spreadsheet

Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway? Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Discussion started by: killaram
6 Replies

5. UNIX for Dummies Questions & Answers

Standard error output to Pipe input - solved

Hi, I want to check a particular word is in standard error output or not. Can I acheive it in single command? For example, Delete file_name 2>error.log cat error.log Output: XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX Successfully deleted XXXXXXXXXXXXXXXXX where delete is... (2 Replies)
Discussion started by: poova
2 Replies

6. Programming

Redirect Standard Output Multi-Process

Hi, I'm trying to compile the following code: /************** Begin <test.c> ***************/ /* * Compiled with: gcc -Wall -o test test.c */ #include <stdio.h> #include <unistd.h> int main(void) { printf("I'm process %d, son of %d \n", getpid(), getppid()); ... (5 Replies)
Discussion started by: djodjo
5 Replies

7. Shell Programming and Scripting

[BASH] redirect standard error and use it inside

Hi all, Maybe my question is too simple but till now i couldn't figure about a solution :( I have a bash script scheduled in cron: <cron time parameters> my_script.sh > result.log 2>&1 By this way i can have standard output and standard error in my result.log file Now i want my script... (2 Replies)
Discussion started by: Pescator
2 Replies

8. Shell Programming and Scripting

redirect only the standard error output to mail

I'm writing a script using file descriptor 2 (std error) to send an email only if the command fails or errors out but the script always emails me irrepective of whether it fails or not. It will not email the /tmp/check.error file output if doesn't error out just the mail with the subject "Cannot... (3 Replies)
Discussion started by: barkath
3 Replies

9. UNIX for Dummies Questions & Answers

Question from a newbie. How to redirect standard output

I have a program that is sending error text to the console and I need to redirect that output to a log file. I'm brand new to Unix and don't know how to do this. Any direction would be greatly appreciated. (1 Reply)
Discussion started by: ndemos
1 Replies

10. UNIX for Dummies Questions & Answers

redirect standard error into log file

Hi, I am new in shell scripting. Can anyone point out what wrong of below script. If I want the error output to "sqlerror.log" and database pool data output to "bulk_main.dat". Right now, the below script, if successful execute, the data will output to bulk_main.dat && sqlerror.log both... (7 Replies)
Discussion started by: epall
7 Replies
Login or Register to Ask a Question