pipes

Unable to change a pipe to be a normal file

I have the following file (above) which seems to be an Unix pipe How can you make the pipe a default text file? ...

bash: redirect and append both stdout and stderr

To redirect stdout in bash, overwriting file cmd > file.txt To redirect stdout in bash, appending to file cmd >> file.txt To redirect both stdout and stderr, overwriting cmd &> file.txt How do I redirect both stdout and stderr appending to file? cmd &>> file.txt does not work for me ...

How to tell if stderr is directing output to a file?

Is there a way I can tell whether stderr is outputting to a file or the terminal within a C/C++ program? I need to output different error message depending on whether the program is invoked as: ./program or like: ./program 2>> file ...

How to redirect Dtrace output when using the -c flag?

How can I redirect only Dtrace's output when running a script with the -C flag? like in this case: dscript.d -s myscript.d -c date Note: I found the answer to my question before posting it, but I'm putting it here so it's part of SO. ...

Is there a way to poll a file handle returned from subprocess.Popen?

Say I write this: from subprocessing import Popen, STDOUT, PIPE p = Popen(["myproc"], stderr=STDOUT, stdout=PIPE) Now if I do line = p.stdout.readline() my program waits until the subprocess outputs the next line. Is there any magic I can do to p.stdout so that I could read the output if it's there, but just continue otherwise? I...

Does Linux's splice(2) work when splicing from a TCP socket?

I've been writing a little program for fun that transfers files over TCP in C on Linux. The program reads a file from a socket and writes it to file (or vice versa). I originally used read/write and the program worked correctly, but then I learned about splice and wanted to give it a try. The code I wrote with splice works perfectly...

How to pipe a command result to a -<character><argument> option? (Without spaces)

Hello! I have this set of piped commands: grep -n '*' file.txt | head -n1 | awk -F\: '{print $1-1;}' It tells me the previous line to that where it first find asterisks. Now I want to get the previous lines piping that to: head -n<that previous line number> Head requires a number following immediately the -n argument, without space...

FIFO (named pipe) messaging obstacles

I plan to use Unix named pipes (mkfifo) for simple multi-process messaging. A message would be just a single line of text. Would you discourage me from that? What obstacles should I expect? I have noticed these limitations: A sender cannot continue until the message is received. A receiver is blocked until there are some data. Nonblo...

Capturing large amounts of output from Apache Commons-Exec

I am writing a video application in Java by executing ffmpeg and capturing its output to standard output. I decided to use Apache Commons-Exec instead of Java's Runtime, because it seems better. However, I am have a difficult time capturing all of the output. I thought using pipes would be the way to go, because it is a standard way o...

why is there asymmetrical behavior in pipes

why is it ok for a reader to exist when there are no writers but not ok for a writer to exist when there are no readers in pipes? . Is it because the reader is meant to wait so it's ok if there is no writer whereas a writer is ready with data and it is not known how long it has to wait even though it has data ready. . Is it because the...

Why is ioctl() not blocking?

I have written code for passing file descriptors between unrelated processes using streams. The server should wait for the client to send a file descriptor. Here is the server code: #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stropts.h> #include <stdio.h> #include <errno.h> #include <unistd.h> ...

Python - simple reading lines from a pipe

I'm trying to read lines from a pipe and process them, but I'm doing something silly and I can't figure out what. The producer is going to keep producing lines indefinitely, like this: producer.py import time while True: print 'Data' time.sleep(1) The consumer just needs to check for lines periodically: consumer.py import ...

How can Unix pipes be used between main process and thread?

I am trying to channel data via pipes whenever a signal arrives from a thread to the main process. Is this possible? How can this be done? The problem: A child thread reads data and puts it into a queue. Main application does its own stuff, however, when data is available on the queue, it should be notified by the thread, and st...

How can I put a pointer on the pipe?

Say I have a pointer to some structure in a thread, and I want to pass it to the parent process via a pipe. Example: MyType * someType; I then want to cast someType to void * and put it on the pipe. How can it be done? ...

How can I pass data from a thread to the parent process?

I have a main process that uses a single thread library and I can only the library functions from the main process. I have a thread spawned by the parent process that puts info it receives from the network into a queue. I need to able to tell the main process that something is on the queue. Then it can access the queue and process the ...

Why do I need to close fds when reading and writing to the pipe?

Here is an example to illustrate what I mean: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main(void) { int fd[2], nbytes; pid_t childpid; char string[] = "Hello, world!\n"; char readbuffer[80]; pipe(fd); if((childpid = fork()) == -1) { ...

Is it possible to get gcc to read from a pipe?

I'm looking for an option to gcc that will make it read a source file from the standard input, mainly so I could do something like this to generate an object file from a tool like flex that generates C code (flex's -t option writes the generated C to the standard output): flex -t lexer.l | gcc -o lexer.o -magic-option-here because I d...

Returning the terminal cursor to start-of-line with wrapping enabled

I'm writing a filter (in a pipe destined for a terminal output) that sometimes needs to "overwrite" a line that has just occurred. It works by passing stdin to stdout character-by-character until a \n is reached, and then invoking special behaviour. My problem regards how to return to the beginning of the line. The first thing I thoug...

Patterns for non-layered applications

In Patterns of Enterprise Application Architecture, Martin Fowler writes: This book is thus about how you decompose an enterprise application into layers and how those layers work together. Most nontrivial enterprise applications use a layered architecture of some form, but in some situations other approaches, such as p...

Using pipes to communicate data between two anonymous python scripts

Consider this at the windows commandline. scriptA.py | scriptB.py I want to send a dictionary object from scriptA.py to scriptB.py by pickle:ing it and sending it over a pipe. But I don't know how to accomplish this. I've read some posts about this subject here, but usually there's answers along these line: Popen( "scriptA.py"´, ......