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
31
votes
4 answers

Best way to Pipe InputStream to OutputStream

I was to trying to find the best way to pipe the InputStream to OutputStream. I don't have an option to use any other libraries like Apache IO. Here is the snippet and output. import java.io.FileInputStream; import java.io.FileOutputStream; import…
Siva Arunachalam
  • 7,582
  • 15
  • 79
  • 132
31
votes
3 answers

Bash: grep pattern from command output

I'm really new with bash, but it's one of the subjects on school. One of the exercises was: Give the line number of the file "/etc/passwd" where the information about your own login is. Suppose USERNAME is my own login ID, I was able to do it…
MarioDS
  • 12,895
  • 15
  • 65
  • 121
30
votes
5 answers

How to get the size of a filtered (piped) set in angular2

I wrote my own filter pipe as it disappeared in angular2: import {Pipe, PipeTransform} from 'angular2/core'; @Pipe({ name: 'myFilter' }) export class MyFilter implements PipeTransform { transform(customerData: Array, args: any[]) { …
neric
  • 3,927
  • 3
  • 21
  • 25
29
votes
5 answers

Pipe string to GNU Date for conversion - how to make it read from stdin?

GNU Date lets you convert date strings like so: $ date +"%d %m %Y" -d "yesterday" 04 01 2012 Is it possible to pipe a date string to it for conversion? I've tried the obvious -d - like so: $ echo "yesterday" | date +"%d %m %Y" -d - but it…
Brian Beckett
  • 4,742
  • 6
  • 33
  • 52
29
votes
4 answers

What's the differences between system and backticks and pipes in Perl?

Perl supports three ways (that I know of) of running external programs: system: system PROGRAM LIST as in: system "abc"; backticks as in: `abc`; running it through a pipe as in: open ABC, "abc|"; What are the differences between them? Here's…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
29
votes
5 answers

Pipe raw OpenCV images to FFmpeg

Here's a fairly straightforward example of reading off a web cam using OpenCV's python bindings: '''capture.py''' import cv, sys cap = cv.CaptureFromCAM(0) # 0 is for /dev/video0 while True : if not cv.GrabFrame(cap) : break …
BrianTheLion
  • 2,618
  • 2
  • 29
  • 46
29
votes
4 answers

Pipe input in to ffmpeg stdin

I am trying to use ffmpeg to decode audio data. While it works to load from a file, I would like to avoid using files because to do so, means I would have to use a temporary. Instead, I'd like to pipe in the data(which I've previously loaded) using…
AbstractDissonance
  • 1
  • 2
  • 16
  • 31
29
votes
1 answer

Windows cmd pass output of one command as parameter to another

In linux it is possible t do this: git diff $(git status -s -b | sed -n '2p' | cut -d' ' -f2-) or a simpler case ls $(pwd) The question is how can I achieve the same in windows? (not using a batch file, a one liner in command prompt). Not all…
Arijoon
  • 2,184
  • 3
  • 24
  • 32
29
votes
7 answers

How do you specify filenames within a zip when creating it on the command line from a pipe?

I'm trying to create a zip file from file contents which are being piped in, e.g. mysql [params and query] | zip -q output.zip - This writes the zip correctly, but when you open the zip, the file within it is called "-". Is there any way of…
user245425
29
votes
1 answer

How to assign an output to a shellscript variable?

How to assign this result to a shell variable? Input: echo '1+1' | bc -l Output: 2 Attempts: (didn't work) #!bin/sh a=echo '1+1' | bc -l echo $a
GarouDan
  • 3,743
  • 9
  • 49
  • 75
29
votes
4 answers

Set $_SERVER variable when calling PHP from command line?

Is it possible to pass a $_SERVER variable to a PHP script via the command line? Specifically I am trying to set the $_SERVER['recipient'] manually so I can test email piping without setting up a mail server.
Ian McIntyre Silber
  • 5,553
  • 13
  • 53
  • 76
28
votes
3 answers

How do you pipe input through grep to another utility?

I am using 'tail -f' to follow a log file as it's updated; next I pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case); finally I'd like to make is piping the output from grep to a…
les2
  • 14,093
  • 16
  • 59
  • 76
28
votes
3 answers

Piping stdin to R

I am having trouble piping stdin to an R script. Here is my toy script test.R: #!/usr/bin/env Rscript while(length(line <- readLines('stdin', n=1, warn=FALSE)) > 0) { write(line, stderr()) # process line } I'd like to go through each line and…
WYi
  • 1,565
  • 2
  • 16
  • 16
28
votes
3 answers

Starting a process with inherited stdin/stdout/stderr in Java 6

If I start a process via Java's ProcessBuilder class, I have full access to that process's standard in, standard out, and standard error streams as Java InputStreams and OutputStreams. However, I can't find a way to seamlessly connect those streams…
John Calsbeek
  • 35,947
  • 7
  • 94
  • 101
28
votes
5 answers

DatePipe is not working correctly in Angular 6

In my Angular application after upgrading from version 5 to 6, this error is occurring when using DatePipe. I'm saving a Date () object that the mat-date-picker creates in the Cloud Firestore with the name of the date_field, when returned try to…
Luiz Ricardo Cardoso
  • 1,554
  • 4
  • 16
  • 37