Questions tagged [pipe]
A Unix pipe connects file descriptors of two processes. A pipe is created with the POSIX pipe() function declared in <unistd.h>. Shells provide pipe creation between processes using "|".
1,884 questions
4
votes
2
answers
489
views
how to tell, from the outside, if the output stream of a process has been closed?
Suppose you have this script, on an Ubuntu machine:
#!/bin/env python3
import sys
import time
try:
i = 1
while True:
print(i)
i += 1
except Exception as e:
sys.stderr.write(f"We ...
0
votes
0
answers
34
views
Why does `<command> | tee /dev/tty | :` (where `:` is the "no effect" or "does nothing" bash builtin) display nothing? [duplicate]
I wanted to use tee /dev/tty to look into the stream passing through a pipeline. While making some tests, I observed the following:
~$ cd /proc/self/fd
/proc/self/fd$ ls
0 1 2 255
# Ok
/proc/self/...
3
votes
1
answer
442
views
Understanding file descriptors and pipes resulting from `cat <(<command>)`
I don't understand the following:
$ cat <(sleep 60) & jobs -l
[1] 63813
[1]+ 63813 Running cat <(sleep 60) &
/proc/63799/fd$ ps --forest
PID TTY TIME CMD
...
-1
votes
1
answer
100
views
Serving a file (e.g. in Apache) from a named pipe (made with mkfifo)
Let's say I use Apache, and that I am in /var/www/html/. I do:
mkfifo test.tar
tar cvf - ~/test/* > test.tar &
In a browser, when trying to download http://localhost/test.tar I get:
...
0
votes
0
answers
33
views
How can I grep the output of ffprobe? [duplicate]
I'd like to only see those lines containing "Stream #" from an ffprobe output. But whatever I do, it continues to show the whole output. Neither "|" nor ">" pipes work....
5
votes
3
answers
532
views
Can grep output the complete input verbatim only if there was a match?
I'm processing input data in a pipeline consisting of several programs. In one step of the pipeline, I want to know if there are certain lines in the input, but I want to output everything as-is ...
0
votes
2
answers
87
views
One-liner piping from find/xargs with paths including spaces
The following question likely does not relate specifically to Vim. I use a Vim example, as this is where I encounter the issue.
Working on Ubuntu, I often open multiple files in Vim using tab pages:
$ ...
10
votes
3
answers
2k
views
bash: echo "hello" | > file.txt results in an empty file
I use the Git Bash on Windows, and stumbled over a strange behaviour. When I execute this command, it creates an empty file:
echo hello | > hello.txt
(hello.txt is empty after this command)
I ...
0
votes
2
answers
179
views
How can I run if statements on a command output without terminating it?
I have to run four separate if statements (and their consequences) on one command output continuously as it updates (doing four different things based on four different strings which might be in the ...
0
votes
1
answer
99
views
What is (if any) the file descriptor of /dev/tty?
The urgent issue to read keyboard input in the pipeline is solved by the answer in https://stackoverflow.com/questions/15230289/read-keyboard-input-within-a-pipelined-read-loop:
mycommand-outputpiped |...
3
votes
2
answers
164
views
What explains this very odd behavior of GNU grep interacting with buffering and pipes and how to stop it?
This is best illustrated with an example I feel:
{ printf 'foo\nbar\n' ; sleep 2 ; } | grep -m1 foo
{ printf 'foo\n' ; sleep 2 ; printf 'bar\n' ; sleep 2 ; } | grep -m1 foo
Both of these commands, ...
3
votes
2
answers
125
views
print_one_line_and_wait_long_time | head -n1: early exit of pipe/process substitution [duplicate]
tl;dr: How to reliably ensure that the pipe a | head -n1 terminates as soon as head terminates?
Motivation: git log --grep="$MAIL_SUBJECT_LINE" --oneline --format=%H | head -n1 takes a long ...
2
votes
2
answers
95
views
Recovery of a compressed image not possible due to lack of Space - general understanding of compression methods
I used gzip to compress an image which is quite huge still.
dd if=/dev/sda2 bs=1M | gzip -c -9 > sda2.dd.img.gz
then I changed the partitioning of the Drive because I wanted to install Linux.
And ...
0
votes
1
answer
84
views
How can I use a here-document on the left-hand side of a pipeline? [duplicate]
Show lines passed by here-document in the stdout:
cat <<EOF
foo
bar
baz
EOF
foo
bar
baz
I want to match some string with grep via pipe:
cat <<EOF
foo
bar
baz
EOF
|grep 'ba'
Why can't ...
0
votes
1
answer
129
views
How can I make writes to named pipe block if the reader closes, and vice versa?
Right now if I write to a name pipe and then close the reader, the writer gets a SIGPIPE and then exits. For example,
$ mkfifo pipe
$ cat pipe & # read from the pipe in the background
$ cat > ...