io-redirection

Is there a way to make linux CLI IO redirection persistent?

I have multiple piped commands, like this: find [options] | grep [options] | xargs grep [options] Each one of them can potentially produce errors (permissions errors, spaces-in-filenames errors, etc) that I am not interested in. So, I want to redirect all errors to /dev/null. I know I can do this with 2>/dev/null, for each command. Ca...

unix shell, redirect output but keep on stdin

I'd like to have a shell script redirect stdout of a child process in the following manner Redirect stdout to a file Display the output of the process in real time I know I could do something like #!/bin/sh ./child > file cat file But that would not display stdout in real time. For instance, if the child was #!/bin/sh echo 1 sl...

unix shell, getting exit code with piped child

Let's say I do this in a unix shell $ some-script.sh | grep mytext $ echo $? this will give me the exit code of grep but how can I get the exit code of some-script.sh EDIT Assume that the pipe operation is immutable. ie, I can not break it apart and run the two commands seperately ...

How can I redirect standard output to a file in Perl?

I'm looking for an example of redirecting stdout to a file using Perl. I'm doing a fairly straightforward fork/exec tool, and I want to redirect the child's output to a file instead of the parents stdout. Is there an equivilant of dup2() I should use? I can't seem to find it ...

Redirect a file stream into memory stream

Hey, I do have a program (call it "a.exe" for example) which reads its config from several files. can I write another program to redirect all file accesses of "a.exe" to another stream (console for example)? I don't have the code of "a.exe" but if I get the source code of a.exe, obviously I can change all the file accesses. but is ther...

Perl, redirect stdout but keep on parent

In perl, after fork()ing I can redirect a child's stdout to a file like so open STDOUT,">",$filename or die $! I'm wondering if there is a way of "copying it", keeping the stdout on the parent's stdout but also copying to a specified file. It should happen in a way that would not require any buffering and the user would see the consol...

can a process create extra shell-redirectable file descriptors?

Can a process 'foo' write to file descriptor 3, for example, in such a way that inside a bash shell one can do foo 1>f1 2>f2 3>f3 and if so how would you write it (in C)? ...

Redirecting in C++

#include <iostream> #include <fstream> using namespace std; void foo(){ streambuf *psbuf; ofstream filestr; filestr.open ("test.txt"); psbuf = filestr.rdbuf(); cout.rdbuf(psbuf); } int main () { foo(); cout << "This is written to the file"; return 0; } Does cout write to the given file? If not, is there a way t...

Run shell command with input redirections from python 2.4?

What I'd like to achieve is the launch of the following shell command: mysql -h hostAddress -u userName -p userPassword databaseName < fileName From within a python 2.4 script with something not unlike: cmd = ["mysql", "-h", ip, "-u", mysqlUser, dbName, "<", file] subprocess.call(cmd) This pukes due to the use of the redirect symb...

Android: invoking a regular Java-style program with i/o redirection

Hi, I have an apk (or .class, whatever) with a 'public static void main'-method (java style) which does some things. Compiling and installing the apk this gives works fine (from eclipse). Now from a regular Android app I would like to invoke that code while redirecting its stdin/stdout to Input-/Output- Stream objects. Is this possibl...

Asynchronous Cmd.exe Output Redirection Problem

I'm using VB.new to create my own custom Command Line Program. It's a windows form Application that starts a new "cmd.exe" process. My Form has one big TextBox which all the cmd.exe's output is displayed to. And it has a smaller text box in which you can type commands to send to cmd.exe. Everything works for the most part. I can send com...

How do these stream redirections work?

From this perldoc page, To capture a command's STDERR and STDOUT together: $output = `cmd 2> To capture a command's STDOUT but discard its STDERR: $output = `cmd 2>/dev/null`; To capture a command's STDERR but discard its STDOUT (ordering is important here): $output = `cmd 2> To exchange a command's STDOUT and STDERR in order to ...

How to ignore program's output when using /usr/bin/time ?

I want to know how long a program running, so I tried "/usr/bin/time ./program > /dev/null". But soon I found it displays program's output to stderr. I tried "/usr/bin/time ./program > /dev/null 2>&1" then, but /usr/bin/time's output not appear. So my question is, how to ignore program's output, and keep time's output. Thanks a lot. ...

redirecting complete make output to a file

Hi I want to redirect complete make output to a file. I tried redirecting the stdout and stderr with the following command: make >aks_file.txt 2>&1 & But that is not redirecting the EXACT complete output which is otherwise generated by issuing just make (some lines are missing) Am I missing something? ...