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
25
votes
1 answer

Check if file is a named pipe (fifo) in python?

I communicate with a named pipe, but I would like to check if it really is a named pipe BEFORE opening it. I check in Google but there is nothing, os.path.isfile() returns False, and I really need to check it.
Mykeul
  • 473
  • 1
  • 5
  • 10
25
votes
9 answers

Inform right-hand side of pipeline of left-side failure?

I've grown fond of using a generator-like pattern between functions in my shell scripts. Something like this: parse_commands /da/cmd/file | process_commands However, the basic problem with this pattern is that if parse_command encounters an error,…
Bittrance
  • 2,202
  • 2
  • 20
  • 29
25
votes
6 answers

Can popen() make bidirectional pipes like pipe() + fork()?

I'm implementing piping on a simulated file system in C++ (with mostly C). It needs to run commands in the host shell but perform the piping itself on the simulated file system. I could achieve this with the pipe(), fork(), and system() system…
Taylor D. Edmiston
  • 12,088
  • 6
  • 56
  • 76
25
votes
8 answers

real time subprocess.Popen via stdout and PIPE

I am trying to grab stdout from a subprocess.Popen call and although I am achieving this easily by doing: cmd = subprocess.Popen('ls -l', shell=True, stdout=PIPE) for line in cmd.stdout.readlines(): print line I would like to grab stdout in…
alfredodeza
  • 5,058
  • 4
  • 35
  • 44
25
votes
5 answers

How to emit/pipe array values as a readable stream in node.js?

What is the best way to create a readable stream from an array and pipe values to a writable stream? I have seen substack's example using setInterval and I can implement that successfully using 0 for the interval value, but I am iterating over a lot…
TankofVines
  • 1,107
  • 2
  • 14
  • 23
25
votes
4 answers

paste without temporary files in Unix

I'm trying to use the Unix command paste, which is like a column-appending form of cat, and came across a puzzle I've never known how to solve in Unix. How can you use the outputs of two different programs as the input for another program (without…
Oliver
  • 261
  • 1
  • 3
  • 4
24
votes
7 answers

Jenkins pipeline sh does not seem to respect pipe in shell command

I am using a Jenkinsfile in a pipeline on version 2.32.2. For various reasons I want to extract the version string from the pom. I was hoping I wouldn't have to add the maven help plugin and use evaluate. I quickly came up with a little sed…
sporkthrower
  • 806
  • 1
  • 7
  • 19
23
votes
2 answers

Differences between %.% (dplyr) and %>% (magrittr)

The dplyr package introduced the %.% operator to pass the left hand side as an argument of the function on the right hand side, similar to a *NIX pipe. The magrittr package is a much more lightweight package that exists to define only that…
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
23
votes
5 answers

How to read to and write from a pipe in Perl?

I need to modify an existing Perl program. I want to pipe a string (which can contain multiple lines) through an external program and read the output from this program. This external program is used to modify the string. Let's simply use cat as a…
kayahr
  • 20,913
  • 29
  • 99
  • 147
22
votes
5 answers

Need to avoid subprocess deadlock without communicate

I need a execute a command that produces a lot of output and takes a lot of time to execute (> 30 minutes). I was thinking of using subprocess.Popen to do it. I need to capture the output of the command, so I pass PIPE to stdout and stderr. A…
GDICommander
  • 1,273
  • 3
  • 15
  • 27
22
votes
3 answers

How to use DecimalPipe from component in angular?

I have a requirement that I have to convert the number using the decimal pipe from ts Instead of use decimal pipe like this {{rmanFmvRulesDef.max | number :'1.2-2'}} I want to manipulate it from the component, can anyone please help me?
Soumya Gangamwar
  • 954
  • 4
  • 16
  • 44
22
votes
2 answers

dplyr . and _no visible binding for global variable '.'_ Note in package check

In dplyr one can write code like e.g. using the '.' to refer to the data in the pipe x <- data.frame(x = 2:4) y <- data.frame(y = 1:3) y %>% dplyr::bind_cols(x,.) but when using it in a function and running the package check it produces the no…
witek
  • 984
  • 1
  • 8
  • 25
22
votes
6 answers

Filter on multiple columns using one pipe angular 2

I am trying to filter Array data based on multiple columns using only one Pipe. Right now, It filters first column value. Please check my below code and help me to sort this out. My Code: @Pipe({ name: "dataFilter", pure: false }) export class…
Jeeten Parmar
  • 5,568
  • 15
  • 62
  • 111
22
votes
3 answers

How do I use the Ant exec task to run piped commands?

I'm trying to run the following command using the 'exec' task in Ant: ls -l /foo/bar | wc -l Currently, I have my exec looking like this:
Steve Griff
  • 651
  • 1
  • 6
  • 16
22
votes
3 answers

Use pipe without feeding first argument

Is the %>% pipe operator always feeding the left-hand side (LHS) to the first argument of the right-hand side (RHS)? Even if the first argument is specified again in the RHS call? Say I want to specify which variable to use in cor():…
Matifou
  • 7,968
  • 3
  • 47
  • 52