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

Subsetting with square brackets while piping with dplyr functions

While I have a (somewhat convoluted) work-around, I'm trying to figure out why subsetting with square brackets ([]) does not work the same when piping results from dplyr functions. For a really simple demonstration. The first two…
michdn
  • 73
  • 1
  • 1
  • 7
3
votes
2 answers

Bash input from pipe

I wrote a trivial bash script which dumps a random line from a file or STDIN: #!/bin/bash if [ $# -ne 1 ] then echo "Syntax: $0 FILE (or \'-\' for STDIN)" echo $0 - display a random line from FILE exit 1 fi RAND=`cat…
entropo
  • 2,481
  • 15
  • 15
3
votes
3 answers

PHP asynchronous reading (shell scripting)

I have a PHP TCP daemon which provides data to clients. One of the features is to get info from "tail -f messages" command. So I have to run this command asynchronously and in case of new data, send it to the clients. I have a problem how to create…
Mejmo
  • 2,363
  • 9
  • 35
  • 54
3
votes
2 answers

Child-Process execution order seems wrong, but works

Why does the following code execute the command: "cat /etc/passwd | wc -l" and not "wc -l | cat /etc/passwd"? Even though the debugging statements are in the order b a int main() { pid_t pid; int fd[2]; int stdOut = dup(1); …
GoodCoffee
  • 43
  • 5
3
votes
3 answers

How to prepend stdout and stderr output with timestamp when redirecting into log files?

In Linux I'm starting a program called $cmd in an init script (SysVInit). I'm already redirecting stdout and stderr of $cmd into two different logfiles called $stdout_log and $stderr_log. Now I also want to add a timestamp in front of every line…
Iniesta8
  • 399
  • 2
  • 15
3
votes
2 answers

How the alternatives are better than using curl | sudo sh

This page says of the "using curl | sudo sh" pattern to: Use this approach when making changes on production server [instead] curl -sf -L https://static.rust-lang.org/rustup.sh -o rustup.sh less rustup.sh chmod +x rustup.sh sudo ./rustup.sh I…
Lance
  • 75,200
  • 93
  • 289
  • 503
3
votes
3 answers

++ Operator on Variable Is Not Changing As Expected In ScriptBlock

I am trying to rename files by putting a prefix based on an incrementing counter in the files such as: $directory = 'C:\Temp' [int] $count=71; gci $directory | sort -Property LastWriteTime | ` rename-item -newname {"{0}_{1}" -f $count++, $_.Name}…
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
3
votes
3 answers

How to escape pipes in .screenrc for commands to run at startup?

I'm using byobu/screen, and I would like to have a new screen session default to containing a few windows set up specially for tailing a specific log file. My .screenrc looks something like this (technically this is my .byobu/windows file): chdir…
matt b
  • 138,234
  • 66
  • 282
  • 345
3
votes
2 answers

Passing a struct with 2 dynamic arrays through a pipe and fork

I have a homework for uni. My homework is to make project using fork and using the method of pipelining to passing data through child and father processess. Well we need to creat two pipes. 1st pipe send a txt file that you will write in there the…
3
votes
1 answer

bash function preserving tab completion

I put the function make_color() { make $1 | ccze -A } in .bashrc to get colored make output. His works fine, but make's tab-completion for selecting targets is lost. Is there any way to preserve the tab-completion of the command in the…
Jonatan Öström
  • 2,428
  • 1
  • 16
  • 27
3
votes
0 answers

Can't escape pipe character in windows CMD when echoing?

I am trying to pipe some commands via echo to plink over serial comport to a linux device. Most short commands work, but when I combined with a linux command that needs a pipe character "|" it breaks. Which makes sense, since cmd or echo thinks…
mwcmwc
  • 39
  • 3
3
votes
1 answer

Infinite loop when using *ngFor with async pipe in Angular

My problem is very similar to this one. In foo.component.html: {{ element | json }} In…
funkid
  • 577
  • 1
  • 10
  • 30
3
votes
0 answers

Mark pipe file descriptor as non writable in Linux

I'm working on a library to create IPC based on UNIX socket on Linux. The goal is to hide the IPC logic in a library and I use a thread which handles the socket for external communication. Since I want to mux/demux data coming from outside to…
hilt0n
  • 376
  • 1
  • 10
3
votes
3 answers

Piping output to a bash function with multiple inputs

Here is what I am trying to do: I want to measure the Levensthein distance between two strings, using bash. I found an implementation of the LD here. Now, suppose that I have some toy data like so: 1 The brown fox jumped The green fox jumped 0…
Astrid
  • 1,846
  • 4
  • 26
  • 48
3
votes
2 answers

overlapping output while reading from fifo: how to fix/avoid this?

I am trying to aggregate data from 2 files, so I decided to send the data via separate writer processes to a named fifo, and launched a separate reader process to read and process the aggregated data. All reading/writing is happening on a ramdisk…
User9102d82
  • 1,172
  • 9
  • 19