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 ). 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.

Every program that runs on the command line has three data streams connected to it: STDIN(0) - standard input, STDOUT (1) - standard output - data printed by the program, STDERR(2) - standard error.

There are ways to connect streams between programs and files called piping and redirections.

Piping is a mechanism for sending data from one program to another using the "|" operator. The operator feeds the output from the program on the left as input to the program on the right.

Example

$ cat two_columns
column1:cloth
column2:strawberries
column3:fish
column4:chocolate
column5:punch cards
$ cat two_columns | awk -F: '{print $1}'
column1
column2
column3
column4
column5 
$ cat two_columns | awk -F: '{print "HAS: " $2}'
HAS: cloth
HAS: strawberries
HAS: fish
HAS: chocolate
HAS: punch cards 

Useful Links

9809 questions
20
votes
1 answer

Using Popen in a thread blocks every incoming Flask-SocketIO request

I have the following situation: I receive a request on a socketio server. I answer it (socket.emit(..)) and then start something with heavy computation load in another thread. If the heavy computation is caused by subprocess.Popen (using…
Schnodderbalken
  • 3,257
  • 4
  • 34
  • 60
20
votes
2 answers

Filtering an array in angular2

I am looking into how to filter an array of data in Angular2. I looked into using a custom pipe, but I feel this is not what I am looking for, as it seems more geared towards simple presentation transformations rather then filtering large sets of…
Witted
  • 422
  • 1
  • 4
  • 14
20
votes
1 answer

Piping to findstr's input

I have a text file with a list of macro names (one per line). My final goal is to get a print of how many times the macro's name appears in the files of the current directory. The macro's names are in C:\temp\macros.txt. type C:\temp\macros.txt in…
Gauthier
  • 40,309
  • 11
  • 63
  • 97
20
votes
2 answers

Bash: replacing a substring in pipe stdin

I try to replace a certain substring from the stdin with a new substring. I have to get the stdin from the pipe, after reading several files by cat. Then I want to push the changed string forward to the pipe. Here is what I try to do: cat file1…
rapt
  • 11,810
  • 35
  • 103
  • 145
20
votes
6 answers

How to read from stdin or from a file if no data is piped in Python?

I have a CLI script and want it to read data from a file. It should be able to read it in two ways : cat data.txt | ./my_script.py ./my_script.py data.txt —a bit like grep, for example. What I know: sys.argv and optparse let me read any args and…
Bite code
  • 578,959
  • 113
  • 301
  • 329
20
votes
1 answer

What's the difference between "here string" and echo + pipe

Wondering what is the right use of here-string (here-document) and pipe. For example, a='a,b,c,d' echo $a | IFS=',' read -ra x IFS=',' read -ra x <<< $a Both methods work. Then what would be the difference between the two functionality? Another…
dragonxlwang
  • 462
  • 5
  • 13
20
votes
3 answers

Non-blocking pipe using popen?

I'd like to open a pipe using popen() and have non-blocking 'read' access to it. How can I achieve this? (The examples I found were all blocking/synchronous)
jldupont
  • 93,734
  • 56
  • 203
  • 318
20
votes
3 answers

How to implement 'set -o pipefail' in a POSIX way - almost done, expert help needed

I have to implement the BASH set -o pipefail option in a POSIX way so that it works on various LINUX/UNIX flavors. To explain a bit, this option enables the user to verify the successful execution of all piped commands. With this option enabled this…
tom.bujok
  • 1,612
  • 2
  • 13
  • 20
20
votes
2 answers

c++ connect output stream to input stream

What I would like to do is create a sort of "pipe" (like a pipe between processes), but between c++ iostreams within the same program. I have a function that requires an input stream as an argument, but my data is coming from an output stream. So is…
Nick
  • 499
  • 5
  • 13
19
votes
5 answers

How do you use Notepad++ regex pipe | for strings longer than one character?

I'm trying to get notepad++ to regex find all instances of "abc" and "def" in the following sentence: The abc went to the def. None of the following syntaxes seem to work: abc|def [abc|def] (abc)|(def) (abc|def) NOTE: "[a|d]" matches any…
TomFuertes
  • 7,150
  • 5
  • 35
  • 49
19
votes
2 answers

Piping program output to less does not display beginning of the output

I am trying to make a bunch of files in my directory, but the files are generating ~200 lines of errors, so they fly past my terminal screen too quickly and I have to scroll up to read them. I'd like to pipe the output that displays on the screen…
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
19
votes
5 answers

how to redirect stdout of 2nd process back to stdin of 1st process?

I have two processes which I need to connect like this: proc1 -- sends output to proc2 proc2 -- sends output to proc1 So far, all pipe examples are of this kind: proc1 | proc2 That's nice, but how do I make the output of proc2 go to proc1? A…
Adrian Herscu
  • 738
  • 1
  • 6
  • 19
19
votes
3 answers

String Resources in Angular

I'm developing an Angular app and I'm looking for something similar to Android Resource available in Android development. Here is the way to get a string in Android: String mystring = getResources().getString(R.string.mystring); I would like to have…
smartmouse
  • 13,912
  • 34
  • 100
  • 166
19
votes
2 answers

Include text in Angular 2+ Date Pipe format

I am attempting to use the DatePipe in Angular 2. I want the output date to be in the format: 08/23/2017 at 11:07 AM. However, I can't figure out the proper way to include the text at in my date format. When I specify the format as such: {{my_date |…
Andrew Mairose
  • 10,615
  • 12
  • 60
  • 102