pipes

How do I capture the output of a command to a file descriptor in Bourne shell?

The standard way to capture command output in Bourne shell is to use the $() syntax: output=$(mycommand) For commands that have a lot of output, however, this requires the shell allocate memory for the whole thing as one long string. I'd prefer to find something that does the moral equivalent of the Unix C function popen, to get a new...

Win32: Determine whether stdout handle is char or wchar stream

I'm writing a win32 utility function for our product that needs to call an arbitrary program via the shell and log its output. We do this by redirecting the stdout from the child process into a pipe: saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; Create...

Redirect stderr and stdout in a bash script

I want to redirect both stdout and stderr of a process to a single file. How do I do that in bash? ...

How can I monitor traffic going through a pipe?

The situation I have is this: I'm redirecting input from one spot in my program to another through a pipe. However, it does not appear that this is working correctly, so I'd like to monitor what's going through the pipe. Currently, I'm using dup2() to simply overwrite the stdin and stdout from the pipe. How can I monitor what's going b...

When pipes are in place and have overwritten stdout and stderr, where does printf go?

I have set up pipes to redirect stderr and stdout. When I use printf, does it send data to stdout or to stream 1? If it sends it to stdout, how can I instead configure it to send data to stream 1? ...

How to read from an os.pipe() without getting blocked?

I'm trying to read from an open os.pipe() to see if it's empty at the moment of the reading. The problem is that calling read() causes the program to block there until there is actually something to read there however there won't be any, if the test I'm doing succeeded. I know I can use select.select() with a timeout however I wanted t...

java.net.SocketException: Broken pipe

I am getting this for all the database connections from my app server.. This exception occured for couple of hours, then got fixed by itself. Something to do with network connection from the appserver? java.net.SocketException: Broken pipe com.inet.tds.SQLException: java.net.SocketException: Broken pipe java.net.SocketException: Broken...

Meaning of wait((int *)0)

One such program that uses a wait function like this is this one: #include<stdio.h> #include<stdlib.h> int main() { int pid,fd[2]; int n; char line[20]; if(pipe(fd)<0) { printf("Error creating pipe"); } else { pid=fork(); if(pid<0) { printf("Error while forking"); } else { if(pid>0) { close(fd[0]); ...

how to read() write() into pipe() via dup2() with stdin and stdout

I need to simulated a Linux command line utility "cal -3" where it will displays three calendar side by side. What I need right now is to get my pipe working. I've been told that I can't use fork(), rather using dup2() and write(), read(), close() to call system("myCustomCommand") tree times. Right now my program does not display calenda...

How do I allow two concurrent processes to communicate?

I have two separate processes: a C program that outputs comma separated values followed by a newline every second, and a Perl program that accepts data (in the same format) and processes this data. The C program outputs (via printf) values as such: 1, 2, 3, 4, 5, 6 7, 8, 9, 10, 11, 12 ... The Perl program sits in an infinite lo...

Win32 named pipes and remote clients

Can I access a named pipe on computer A from computer B given computer A's IP address? If so, what do I need to do to make this happen? ...

run the output of a script as a standalone bash command

suppose you have a perl script "foobar.pl" that prints the following to stdout date -R and you want to run whatever that perl script outputs as a standalone bash command (don't worry about security problems as this is running in a trusted environment). How do you get bash to recognize this as a standalone command? I've tried using x...

Is there a way to output debug messages in Perl that are not piped?

Is there a way to output debug messages in Perl that are not piped? I have a Perl script that I use in a pipe but I really want to print some diagnostic information to the screen instead of to the pipe. ...

How to capture output of execvp

I'm developing a program which executes a program using execvp. It needs to capture the results of the child process and parse them in the main process. It seems there is a way, using named pipes, and duping. I'm trying to hunt down a good example of this, but so far no luck. If anyone has any pointers, links and/or suggestions about thi...

Python subprocess "object has no attribute 'fileno'" error

This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 Code: def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE) proc.append(Popen(['tr', r"...

What's the differences between system and backticks and pipes in Perl?

Perl supports three ways (that I know of) of running external programs: system: system PROGRAM LIST as in: system "abc"; backticks as in: `abc`; running it through a pipe as in: open ABC, "abc|"; What are the differences between them? Here's what I know: You can use backticks and pipes to get the output of the command ...

How to make a pipe loop in Zsh?

Penz says that the problem could be solved by Multios and coproc features in the thread. However, I am unsure about the solution. I do know that you can use multios as ls -1 > file | less but I have never used such that you have two inputs. How can you use these features to have a pipe loop in Zsh? ...

Number of bytes read from a pipe

When reading from a pipe in Linux (C, fread/similar), when EOF is reached, how can it be known how many bytes were read? If I read blocks at a time, fread() only returns the number of full blocks read in, and I can't read one byte at a time because that is too slow. Of course, ftell() returns -1. ...

How to pipe list of files returned by find command to cat to view all the files

Hi, I am doing a find and then getting a list of files. how do I pipe it to another utility like cat (so that cat displays the contents of all those files) and basically need to grep something from these files. ...

Problem with a Python program using os.pipe and os.fork()

Hello, I've recently needed to write a script that performs an os.fork() to split into two processes. The child process becomes a server process and pases data back to the parent process using a pipe created with os.pipe(). The child closes the 'r' end of the pipe and the parent closes the 'w' end of the pipe, as usual. I convert the re...