EzDevInfo.com

Pipe

A Python library to use infix notation in Python

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?


Source: (StackOverflow)

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: Permission denied

How can I get this to work?


Source: (StackOverflow)

Advertisements

Bash script, read values from stdin pipe

I am trying to get bash to process data from stdin that gets piped it, but no luck, what I mean is none of the following work:

echo "hello world" | test=($(< /dev/stdin)); echo test=$test
test=


echo "hello world" | read test; echo test=$test
test=


echo "hello world" | test=`cat`; echo test=$test
test=

where I want the output to be test=hello world. Note I've tried putting "" quotes around "$test" that doesn't work either.


Source: (StackOverflow)

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?


Source: (StackOverflow)

When should I use GCC's -pipe option?

The GCC 4.1.2 documentation has this to say about the -pipe option:

-pipe

Use pipes rather than temporary files for communication between the various stages of compilation. This fails to work on some systems where the assembler is unable to read from a pipe; but the GNU assembler has no trouble.

I assume I'd be able to tell from error message if my systems' assemblers didn't support pipes, so besides that issue, when does it matter whether I use that option? What factors should go into deciding to use it?


Source: (StackOverflow)

How to send a simple string between two programs using pipes?

I tried searching on the net, but there are hardly any resources. A small example would suffice.

EDIT I mean, two different C programs communicating with each other. One program should send "Hi" and the other should receive it. Something like that.


Source: (StackOverflow)

Detect if stdin is a terminal or pipe in C/C++/Qt?

When I execute "python" from the terminal with no arguments it brings up the Python interactive shell.

When I execute "cat | python" from the terminal it doesn't launch the interactive mode. Somehow, without getting any input, it has detected that it is connected to a pipe.

How would I do a similar detection in C or C++ or Qt?


Source: (StackOverflow)

Redirect stdout and stderr to a single file

I'm trying to redirect all output (stdout + stderr) of a dos command to a single file:

C:\>dir 1> a.txt 2> a.txt
The process cannot access the file because it is being used by another process.

Is it possible, or should I just redirect to two separate files?


Source: (StackOverflow)

Piping buffer to external command in Vim

I am kind of a Vim novice. I would like to send contents of the current buffer to stdin of external command (lets say mail). My final purpose is to set a shortcut to quickly send email from current Vim buffer. I am guessing this should be a trivial stuff, but I couldn't find a way to send Vim buffer to an external command. Thanks in advance.


Source: (StackOverflow)

Python subprocess command with pipe

I want to use subprocess.check_output() with ps -A | grep 'process_name'. I tried various solutions but so far nothing worked. Can someone guide me how to do it?


Source: (StackOverflow)

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

Source: (StackOverflow)

How to pipe stderr, and not stdout?

I have a program that writes information to stdout and stderr, and I need to grep through what's coming to stderr, while disregarding stdout.

I can of course do it in 2 steps:

command > /dev/null 2> temp.file
grep 'something' temp.file

but I would prefer to be able to do is without temp files. Any smart piping trick?


Source: (StackOverflow)

With bash, how can I pipe standard error into another process?

It's well known how to pipe the standard ouput of a process into another processes standard input:

proc1 | proc2

But what if I want to send the standard error of proc1 to proc2 and leave the standard output going to its current location? You would think bash would have a command along the lines of:

proc1 2| proc2

But, alas, no. Is there any way to do this?


Source: (StackOverflow)

What are named pipes?

What are they and how do they work?

Context happens to be SQL Server


Source: (StackOverflow)

catching error codes in a shell pipe

I currently have a script that does something like

./a | ./b | ./c

I want to modify it so that if any of a, b or c exit with an error code I print an error message and stop instead of piping bad output forward.

What would be the simplest/cleanest way to do so?


Source: (StackOverflow)