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
3 answers

How to pass a command stdout to lldb debugged file stdin via pipe

I want to run an executable, redirect it's stdout to my program's via pipe, and LLDB debug my program. So, for example: cat my_file | ./main and then debug ./main. I'm aware of process launch -i my_file, but that's not exactly what I want to do -…
Gal Gofrit
  • 31
  • 3
3
votes
1 answer

Problem with Node.js and child_process.exec arguments

On the command line, if I run echo -n "foo" | openssl aes-128-cbc -k "key" -base64 -e (the -n flag prevents echo from adding a newline to the end of its output), I get U2FsdGVkX1+nMW5I4eZSasPKfsUuCpbFsnn56ngEdec= But when I run exec =…
Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
3
votes
0 answers

RSelenium and seleniumPipes use of queryRD

I can get the following to work and the rest of my code functions as well: library(RSelenium) ecap <- list(chromeOptions = list(args = c('--headless', '--disable-gpu'))) rD <- rsDriver(browser = "chrome", geckover=NULL, iedrver=NULL,…
user102452
  • 61
  • 4
3
votes
1 answer

How to capture intermediate error in python subprocess's piped execution

Following python doc to replace shell-pipeline, I have a piece of code that looks like this. p1 = Popen(["tac" , "/var/log/some_process_log.output"], stderr=PIPE, stdout=PIPE) p2 = Popen(["head", "-n", "1000"], stdin=p1.stdout,…
Yogesh lele
  • 392
  • 4
  • 17
3
votes
3 answers

Angular observable with ngFor

I'm building a simple web application using angular. In my template i want to show a list of teachers. From the server i'm getting this kind of json() { users : [{user1}, {user2}, {user3} ] } this is my service file. @Injectable() export class…
Buddhika Chathuranga
  • 1,334
  • 2
  • 13
  • 22
3
votes
3 answers

How to prevent "UnicodeDecodeError" when reading piped input from sys.stdin?

I am reading some mainly HEX input into a Python3 script. However, the system is set to use UTF-8 and when piping from Bash shell into the script, I keep getting the following UnicodeDecodeError error: UnicodeDecodeError: ('utf-8' codec can't…
not2qubit
  • 14,531
  • 8
  • 95
  • 135
3
votes
1 answer

How to read password line after pipe input to Perl script

I'm trying to read STDIN and then get user input line without displaying it in terminal. The Term::ReadKey's solution with ReadMode('noecho') will not work because it uses and if it is not empty it immediately takes(that what is supposed to…
BladeMight
  • 2,670
  • 2
  • 21
  • 35
3
votes
4 answers

tail -F log.log | grep ResponseTime | cut -d = -f 2

I have a live log file called log.log and want to catch some matching patterns and values in it: Example: log.log is growing and we are searching for lines that have pattern "ResponseTime = VALUE" and we want to extract the matched VALUE: I am…
NaMo
  • 31
  • 1
  • 3
3
votes
1 answer

Redirecting of jq output

In a terminal this works fine: mosquitto_sub -h 192.168.178.20 -t tele/POW/SENSOR/# | jq '.ENERGY|.Power' Every 10 seconds there is an output on screen because the device POW publishes it's sensor dates every 10 seconds. The output of mosquitto_sub…
JoergZ
  • 31
  • 1
3
votes
3 answers

Popen.communicate is stuck until process spawned by sub-process terminates

I have the below three scripts, and when I run main.py file, it spawns child.py which again executes the subchild.py and terminates quicly, subchild.py however keeps executing for a lot of time. The problem with this is, main.py is blocked at…
vikkyhacks
  • 3,190
  • 9
  • 32
  • 47
3
votes
1 answer

What is the difference between `cat |` and `<`

I'd like to send the contents of filename to some_cmd on the command line. What's the difference between running this: $ cat filename | some_cmd and $ some_cmd < filename Are there cases where I can or should use one and not the other?
Ashton Wiersdorf
  • 1,865
  • 12
  • 33
3
votes
1 answer

Reduced named pipe (fifo) throughput with nodejs consumer

I am trying to use a named pipe to pass a stream of images from a python process to a nodejs process, ideally at 60 frames per second for 1 megabyte images. The throughput I'm getting is only around 25 frames per second. I was surprised that it was…
3
votes
1 answer

Exit tail upon string detection

I'm writing a barrier to stall the execution of a script until a certain keyword is logged. The script is pretty simple: tail -F -n0 logfile.log | while read LINE; do [[ "$LINE" == *'STOP'* ]] && echo ${LINE} && break; done or tail -F -n0…
Cavaz
  • 2,996
  • 24
  • 38
3
votes
1 answer

CURL chunked POST from infinite pipe?

I want to continuously post an infinite binary data stream to a webserver. So I'm using the following command: curl -X POST -H "Transfer-Encoding: chunked" -d 'hello' http://127.0.0.1:9000 As a test, I'm piping the output of the 'yes' command: $…
Ace17
  • 81
  • 2
  • 6
3
votes
2 answers

Using grep to search for multiple keywords on different lines

I'm completing a command line game/challenge that involves solving a murder mystery. One of the steps is to search for a suspect by using grep to search for multiple keywords in one file. However that file contains thousands of lines of text that…
1 2 3
99
100