Re: What's the difference pipe vs redirection is the following case case.
- From: gordonb.rfiub@xxxxxxxxxxx (Gordon Burditt)
- Date: Sat, 21 Jun 2008 21:40:42 -0500
When I execute party, it brings up a chat line. Ie
m-net% party
Welcome to PARTY! Type '?' for help:
triluda: my hero
mickeyd: are we cheech'n'chongish enough?
When I do the following
m-net% party | /dev/null
zsh: permission denied: /dev/null
I get permission denied.
But when I do something like the following
m-net% party > /dev/null
Welcome to PARTY! Type '?' for help:
eThe output from party gets redirected to /dev/null
What's the difference between the two? Ie, why do I get permission
denied when I try to pipe party to /dev/null?
Because you can pipe to another process but not a file. '|' is
for connecting the stdout of the process on the left hand side
to the stdin of the process of the right hand side. '>' is for
redirecting the stdout of the left hand side process to a file
on the right hand side. You get permission denied for
m-net% party | /dev/null
because it instructs the shell to start the program /dev/null
but, when the shell tries to do so, it finds that /dev/null
hasn't the executable bit set (which makes sense since /dev/null
isn't an executable but just a "file", not a program).
Maybe I'm overcomplicated this a bit, but what's the difference
between an executable, a "file", and a program? I thought an
executable was a program.
"executable" and "program" mean roughly the same thing, if you don't
get into too many arguments over shared libraries and unlinked
object code. Executables are files. Files are not necessarily
executable.
A file with no execute permission cannot be executed as though
it were a program. That's what:
party | /dev/null
is attempting to do. A file that is not a valid executable file
(e.g. because it doesn't contain any code but contains only porn,
last week's grocery list, or pirated music, or contains code for
the wrong CPU type, or something the OS doesn't support) also cannot
be run as a program. If it has execute permission the shell may
attempt to run it as a shell script, which is usually something
between hilarious and a disaster.
You also can't do:
m-net% /dev/null
OR
m-net% party ; /dev/null
for the same reasons, although the second one will appear to work
until you exit party.
You can, as root, cd to the directory containing party, then:
m-net# cat /dev/null > party
but it's not recommended since you'll replace "party" with an empty
file, and it will quit working.
.
- References:
- What's the difference pipe vs redirection is the following case case.
- From: K-mart Cashier
- Re: What's the difference pipe vs redirection is the following case case.
- From: Jens Thoms Toerring
- Re: What's the difference pipe vs redirection is the following case case.
- From: K-mart Cashier
- What's the difference pipe vs redirection is the following case case.
- Prev by Date: Re: What's the difference pipe vs redirection is the following case case.
- Next by Date: Re: Invoking external processes in threaded program
- Previous by thread: Re: What's the difference pipe vs redirection is the following case case.
- Next by thread: Re: What's the difference pipe vs redirection is the following case case.
- Index(es):
Relevant Pages
|