Questions tagged [pipe]
A pipe is an interprocess connection between file descriptors of two processes. A pipe is created with the POSIX pipe() function (from <unistd.h>). Shells create pipes between processes if the "|" symbol is used: "cmd1 | cmd2" directs the output of cmd1 to the input of cmd2. On Windows use CreatePipe(). This mechanism redirects standard input, standard output, and standard error into the calling process in .NET and Java.
10,302
questions
1277
votes
11
answers
603k
views
How can I pipe stderr, and not stdout?
I have a program that writes information to stdout and stderr, and I need to process the stderr with grep, leaving stdout aside.
Using a temporary file, one could do it in two steps:
command > /dev/...
852
votes
7
answers
700k
views
How can I redirect Windows cmd standard output and standard error to a single file?
I'm trying to redirect all output (standard output and standard error) of a Windows command to a single file:
C:\
cd \
dir 1> a.txt 2> a.txt
Output:
The process cannot access the file because ...
530
votes
17
answers
213k
views
Pipe output and capture exit status in Bash
I want to execute a long running command in Bash, and both capture its exit status, and tee its output.
So I do this:
command | tee out.txt
ST=$?
The problem is that the variable ST captures the ...
388
votes
8
answers
395k
views
How to use `subprocess` command with pipes
I want to use subprocess.check_output() with ps -A | grep 'process_name'.
I tried various solutions but so far nothing worked. Can someone guide me how to do it?
349
votes
6
answers
104k
views
How can I detect if my shell script is running through a pipe?
How do I detect from within a shell script if its standard output is being sent to a terminal or if it's piped to another process?
The case in point: I'd like to add escape codes to colorize output, ...
336
votes
7
answers
653k
views
Retrieving the output of subprocess.call() [duplicate]
How can I get the output of a process run using subprocess.call()?
Passing a StringIO.StringIO object to stdout gives this error:
Traceback (most recent call last):
File "<stdin>", ...
304
votes
5
answers
107k
views
How to pipe stdout while keeping it on screen ? (and not to a output file)
I would like to pipe standard output of a program while keeping it on screen.
With a simple example (echo use here is just for illustration purpose) :
$ echo 'ee' | foo
ee <- the output I would ...
266
votes
17
answers
420k
views
Read values into a shell variable from a pipe
I am trying to get bash to process data from stdin that gets piped into, but no luck. What I mean is none of the following work:
echo "hello world" | test=($(< /dev/stdin)); echo test=$test
test=
...
262
votes
4
answers
93k
views
Piping command output to tee but also save exit code of command [duplicate]
I have a shell script in which I wrap a command (mvn clean install), to redirect the output to a logfile.
#!/bin/bash
...
mvn clean install $@ | tee $logfile
echo $? # Does not show the return code ...
260
votes
15
answers
389k
views
How to pipe list of files returned by find command to cat to view all the files
I am doing a find to get a list of files.
How do I pipe it to another utility like cat so that cat displays the contents of all those files?
Afterwards, I'd use grep on that to search some text in ...
248
votes
19
answers
505k
views
Why does cURL return error "(23) Failed writing body"?
It works ok as a single tool:
curl "someURL"
curl -o - "someURL"
but it doesn't work in a pipeline:
curl "someURL" | tr -d '\n'
curl -o - "someURL" | tr -d '\n'
it returns:
(23) Failed writing ...
243
votes
3
answers
154k
views
Piping both stdout and stderr in bash?
It seems that newer versions of bash have the &> operator, which (if I understand correctly), redirects both stdout and stderr to a file (&>> appends to the file instead, as Adrian ...
243
votes
2
answers
135k
views
How to use `jq` in a shell pipeline?
I can't seem to get jq to behave "normally" in a shell pipeline. For example:
$ curl -s https://api.github.com/users/octocat/repos | jq | cat
results in jq simply printing out its help ...
220
votes
5
answers
208k
views
What are the parameters for the number Pipe - Angular 2
I have used the number pipe below to limit numbers to two decimal places.
{{ exampleNumber | number : '1.2-2' }}
I was wondering what the logic behind '1.2-2' was? I have played around with these ...
216
votes
8
answers
623k
views
How to open every file in a folder
I have a python script parse.py, which in the script open a file, say file1, and then do something maybe print out the total number of characters.
filename = 'file1'
f = open(filename, 'r')
content =...