pipe

Unix/Linux pipe behavior when reading process terminates before writing process

两盒软妹~` 提交于 2019-12-23 04:28:57
问题 I have this: $ ls -lh file -rw-r--r-- 1 ankur root 181M Sep 23 20:09 file $ head -6 file z abc abc abc abc abc $ cat file | grep -m 1 z z Question: Why is the cat command line in the last line not dying prematurely with SIGPIPE? I think this should happen because grep terminates in no time compared to cat file that cats 183MB of file. With reading process gone cat will try to write to a broken pipe and should die with SIGPIPE. Update: I ended up writing this: readstdin.c # include <unistd.h>

Is there any way to detect whether client pipe's handle is closed when using NamedPipe?

匆匆过客 提交于 2019-12-23 03:11:04
问题 I am wondering if there is a way to detect the status of client pipe's handle from the server side on Windows platform. Even though the client closed the pipe(disconnected) with CloseHandle() function, there seems to be no way to detect it from the server side. Using WaitForSingleObject() with handle object returns WAIT_OBJECT_0 , regardless of the status of client handle. So, what would be a good solution to detect whether client pipe's handle is closed or not from server side with less cost

How to display the output of a Linux command on stdout and also pipe it to another command? [duplicate]

二次信任 提交于 2019-12-23 02:52:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to pipe stdout while keeping it on screen ? (and not to a output file) For example I want to run the command: ls -l Then I have the output to stdout: drwxr-xr-x 2 user user 4096 Apr 12 12:34 Desktop -rw-rw-r-- 1 user user 1234 Apr 12 00:00 file And I want to redirect this output to another command for some further processing (like redirecting to 'head -1' to extract first line). Can I do it in just one line?

equivalent of select for pipes on windows

左心房为你撑大大i 提交于 2019-12-23 02:39:23
问题 I need to block until one of my pipes has data to be read. I have tried WaitForMultipleObjects but it just returns immediately saying that one of the pipes has data. A subsequent ReadFile on the pipe blocks. I cannot use PeekNamedPipe because I need to block until data is available, and peeking in a loop with sleep would result in a delayed reaction because of the sleep. This code is cross-platform and everything works great on linux because I can use Select on a set of fifo fd's and then

How to get the formatted view of YQL as result?

余生长醉 提交于 2019-12-23 01:36:21
问题 YQL gives out result only in tree view. Is there any way to get the result in Formatted view?? 回答1: Use an XSLT stylesheet to create a formatted view. Here is an example for an RSS feed: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="XML" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd indent="yes"/> <xsl

C++ Gnuplot pipe input from C++ defined variables

只愿长相守 提交于 2019-12-23 00:28:16
问题 I am using C++ to pipe commands to gnuplot using the following code: FILE *gnuplotPipe = popen("gnuplot -persist", "w"); // Open a pipe to gnuplot if (gnuplotPipe) { // If gnuplot is found fprintf(gnuplotPipe, "reset\n"); //gnuplot commands fprintf(gnuplotPipe, "n='500'\n"); fprintf(gnuplotPipe, "max='1500'\n"); fprintf(gnuplotPipe, "min='-1500\n"); fprintf(gnuplotPipe, "width=(max-min)/n\n"); fprintf(gnuplotPipe, "hist(x,width)=width*floor(x/width)+width/2.0\n"); fprintf(gnuplotPipe, "set

18 File Duplication and Pipes

别说谁变了你拦得住时间么 提交于 2019-12-22 23:58:58
1 Resource Duplication Across Forks 子进程是父进程的复制,在 fork 瞬间复制所有信息 复制父进程的代码 复制父进程的状态,包含全部的内存空间,比如变量 /*shared_variable.c*/ int main ( int argc , char * argv [ ] ) { int status ; pid_t cpid , pid ; int i = 0 ; while ( 1 ) { //loop and fork children cpid = fork ( ) ; if ( cpid == 0 ) { /* CHILD */ pid = getpid ( ) ; printf ( "Child: %d: i:%d\n" , pid , i ) ; //set i in child to something differnt i * = 3 ; printf ( "Child: %d: i:%d\n" , pid , i ) ; _exit ( 0 ) ; //NO FORK BOMB!!! } else if ( cpid > 0 ) { /* PARENT */ //wait for child wait ( & status ) ; //print i after waiting printf ( "Parent: i:%d

Java read a logfile live

孤者浪人 提交于 2019-12-22 17:32:05
问题 I'm writing a cod4 server controller in Java(I know there are perfectly fine server controllers out there, but I want to learn from it). Now I want to take specific actions according to entries in a logfile, this file is updated by cod very often, and the file can get quite large. Now how do I efficiently read only the part that has changed of the file, every second or so? Or is there a way to send everything that is changed in the logfile live to Java?(I read something about pipes). The

Java read a logfile live

☆樱花仙子☆ 提交于 2019-12-22 17:31:28
问题 I'm writing a cod4 server controller in Java(I know there are perfectly fine server controllers out there, but I want to learn from it). Now I want to take specific actions according to entries in a logfile, this file is updated by cod very often, and the file can get quite large. Now how do I efficiently read only the part that has changed of the file, every second or so? Or is there a way to send everything that is changed in the logfile live to Java?(I read something about pipes). The

Suppress output to StdOut when piping echo

允我心安 提交于 2019-12-22 14:59:12
问题 I'm making a bash script that crawls through a directory and outputs all files of a certain type into a text file. I've got that working, it just also writes out a bunch of output to console I don't want (the names of the files) Here's the relevant code so far, tmpFile is the file I'm writing to: for DIR in `find . -type d` # Find problem directories do for FILE in `ls "$DIR"` # Loop through problems in directory do if [[ `echo ${FILE} | grep -e prob[0-9]*_` ]]; then `echo ${FILE} >> $