Home > Archive > Unix Programming > August 2005 > command line pipes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
command line pipes
|
|
| Lowell Kirsh 2005-08-22, 9:57 pm |
| First, if this is the wrong group for this please tell where I should go.
I want to send a command's stdout to /dev/null and its stderr to stdout
so that I can pipe it to another program. I tried:
prog1 > /dev/null 2>&1 | prog2
but this does not work. Is there an easy way to do this without using
temporary files?
Lowell
| |
| John W. Krahn 2005-08-23, 3:57 am |
| Lowell Kirsh wrote:
> First, if this is the wrong group for this please tell where I should go.
>
>
> I want to send a command's stdout to /dev/null and its stderr to stdout
> so that I can pipe it to another program. I tried:
>
> prog1 > /dev/null 2>&1 | prog2
>
> but this does not work. Is there an easy way to do this without using
> temporary files?
prog1 2>&1 >/dev/null | prog2
John
--
use Perl;
program
fulfillment
| |
| Floyd L. Davidson 2005-08-23, 3:57 am |
| Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
>First, if this is the wrong group for this please tell where I should go.
>
>I want to send a command's stdout to /dev/null and its stderr to
>stdout so that I can pipe it to another program. I tried:
>
>prog1 > /dev/null 2>&1 | prog2
>
>but this does not work. Is there an easy way to do this without
>using temporary files?
That depends on which shell you are using, and you didn't specify
which one it is. Here's a solution for bash, which will also show
you what to look for in the appropriate man page for your specific
shell.
First, redirect 2 (stderr) to a duplicated stdout, then redirect stdout
to /dev/null, and then you can pipe stdout to another program:
prog1 2>/dev/stdout >/dev/null | prog2
For example:
$ls xx 2>/dev/stdout >/dev/null | grep x
/bin/ls: xx: No such file or directory
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@apaflo.com
| |
| Lowell Kirsh 2005-08-23, 7:57 am |
| I haven't tried this solution yet, but it sounds right. I didn't know
that there was a /dev/stdout. That actually makes a lot of sense.
Floyd L. Davidson wrote:
> Lowell Kirsh <lkirsh@cs.ubc.ca> wrote:
>
>
>
> That depends on which shell you are using, and you didn't specify
> which one it is. Here's a solution for bash, which will also show
> you what to look for in the appropriate man page for your specific
> shell.
>
> First, redirect 2 (stderr) to a duplicated stdout, then redirect stdout
> to /dev/null, and then you can pipe stdout to another program:
>
> prog1 2>/dev/stdout >/dev/null | prog2
>
> For example:
>
> $ls xx 2>/dev/stdout >/dev/null | grep x
> /bin/ls: xx: No such file or directory
>
| |
| Lowell Kirsh 2005-08-23, 7:57 am |
| This doesn't seem to work. I think that stderr is also being sent to
/dev.null.
John W. Krahn wrote:
> Lowell Kirsh wrote:
>
>
>
> prog1 2>&1 >/dev/null | prog2
>
>
>
> John
|
|
|
|
|