pipes

Bash Pipe Handling

Does anyone know how bash handles sending data through pipes? cat file.txt | tail -20 Does this command print all the contents of file.txt into a buffer, which is then read by tail? Or does this command, say, print the contents of file.txt line by line, and then pause at each line for tail to process, and then ask for more data? The...

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 to System.in, System.out, and System.err. It's possible to use redirectErrorStream() to g...

Overlapped I/O on anonymous pipe

Is it possible to use overlapped I/O with an anonymous pipe? CreatePipe() does not have any way of specifying FILE_FLAG_OVERLAPPED, so I assume ReadFile() will block, even if I supply an OVERLAPPED-structure. ...

How can I send the stdout of one process to multiple processes using (preferably unnamed) pipes in Unix (or Windows)?

I'd like to redirect the stdout of process proc1 to two processes proc2 and proc3: proc2 -> stdout / proc1 \ proc3 -> stdout I tried proc1 | (proc2 & proc3) but it doesn't seem to work, i.e. echo 123 | (tr 1 a & tr 1 b) writes b23 to stdout instead of a23 b23 ...

How do I use sudo to redirect output to a location I don't have permission to write to?

I've been given sudo access on one of our development RedHat linux boxes, and I seem to find myself quite often needing to redirect output to a location I don't normally have write access to. The trouble is, this contrived example doesn't work: sudo ls -hal /root/ > /root/test.out I just receive the response: -bash: /root/test.out: ...

Why does "piping" a CharBuffer hang?

Why does the following method hang? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append(buf.flip()); } } ...

Java idiom for "piping"

Is there a more concise/standard idiom (e.g., a JDK method) for "piping" an input to an output in Java than the following? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while( in.read(buf) >= 0 ) { out.append(buf.flip()); buf.clear(); } } [EDIT] Please not...

Connecting input _and_output between of two commands in shell/bash

I have two (UNIX) programs A and B that read and write from stdin/stdout. My first problem is how to connect the stdout of A to stdin of B and the stdout of B to the stdin of A. I.e., something like A | B but a bidirectional pipe. I suspect I could solve this by using exec to redirect but I could not get it to work. The programs are int...

Setting up pipelines reading from named pipes without blocking in bash

I'm looking to call a subprocess with a file descriptor opened to a given pipe such that the open() call does not hang waiting for the other side of the pipe to receive a connection. To demonstrate: $ mkfifo /tmp/foobar.pipe $ some_program --command-fd=5 5</tmp/foobar.pipe In this case, some_program is not run until some process has ...

Can pipes be used across LAN computers?

Can pipes be used across LAN computers? In particular I'm looking for Windows, but if you have more info on other platforms, that will also help others who find this thread later. ...

Why are pipes considered dangerous to use in Windows/unix/linux?

Why are pipes considered dangerous to use? What can be done to avoid these security issues? I'm mostly interested in Windows, but if you have other OS information, please provide. ...

What are the differences between pipes in Windows and Linux?

What are the differences between pipes in Windows and Linux? ...

get command output in pipe, C for Linux

I need to run a Linux CLI command and get its stdout output from C. I can use pipe() to create a pipe, then fork/exec, redirecting child's stdout descriptor into the pipe before calling exec(), and reading from the pipe in parent. Plus I'll need to wait on the child. Is there a simple call to do fork + redirect + exec + wait, like syst...

In **portable C**, how to launch a command connecting the command's stdin to the launcher's stdout?

In a C program (p1), how to launch a dynamically constructed command (and its arguments) that reads its standard input from p1's standard output? Note that: A method other than this stdout --> stdin piping is also OK provided it is PORTABLE across Windows and Linux. I cannot use C++, Java, Perl, Ruby, Python, etc here. Also, will t...

Are pipes considered dangerous to use in Windows, from a security standpoint?

Are pipes considered dangerous to use in Windows, from a security standpoint? ...

Crossplatform Bidirectional IPC

I have a project that I thought was going to be relatively easy, but is turning out to be more of a pain that I had hoped. First, most of the code I'm interacting with is legacy code that I don't have control over, so I can't do big paradigm changes. Here's a simplified explanation of what I need to do: Say I have a large number of si...

How can I get a list of all open named pipes in Windows?

Is there an easy way to test whether your named pipe is working correctly? I want to make sure that the data I'm sending from my app is actually being sent. Is there a quick and easy way to get a list of all the named pipes? ...

How do I use subprocess.Popen to connect multiple processes by pipes?

How do I execute the following shell command using the Python subprocess module? echo "input data" | awk -f script.awk | sort > outfile.txt The input data will come from a string, so I don't actually need echo. I've got this far, can anyone explain how I get it to pipe through sort too? p_awk = subprocess.Popen(["awk","-f","script.a...

Linux kernel /proc FIFO/pipe

I'm currently trying to create a kernel module that will produce data based on kernel events and push them to a file. After reading that this is bad (and I agree), I decided it would make more sense to have the data in a /proc file that a user program could pull from when necessary. However, this idea led to all sorts of problems, part...

Cross-platform (linux/Win32) nonblocking C++ IO on stdin/stdout/stderr

I'm trying to find the best solution for nonblocking IO via stdin/stdout with the following characteristics: As long as there is enough data, read in n-sized chunks. If there's not enough data, read in a partial chunk. If there is no data available, block until there is some (even though it may be smaller than n). The goal is to allo...