I was asked to clarify the question. I'm not asking about any specific program's behavior, but I used ffmpeg as an example of the behavior I'm asking about. To restate the question:

When a program's stdout is piped to another program, how does that program also produce terminal output. Is stderr the only option in terms of output streams?

Original question:

I'm a long-time Windows developer slowly learning my way around Linux to support various electronics and programming hobbies. I'm working with some headless Raspberry Pi's, so I only interact with them through an ssh terminal. I had thought terminal output was just stdout, and indeed when I control a child process launched from a .NET Core program via the Process class, the terminal output is what my program receives when it intercepts the stdout stream.

But I need to launch bash so that I can pipe ffmpeg to VLC, and I realized when I do this from the terminal "by hand", ffmpeg writes processing details to the terminal while simultaneously piping data to VLC. I had thought a command-line pipe redirects stdout to another program's stdin.

I was having trouble with bash (it doesn't seem to pass stdin data from my program to the programs launched with the bash -c "ffmpeg ... | cvlc ..." switch), so I was considering using two Process instances and handling the pipe that way.

Then it occurred to me to wonder about the relationship of terminal output versus pipe output, and what's really going on behind the scenes.

Edit: When I wrote that, I forgot that I typically capture and output both stdout and stderr using the Process class. Under Windows, stderr is rarely used in my experience, is it perhaps routine in Unix to use stderr for non-error terminal output? Just a guess...

  • 1
    There are usually two output streams, "stdout" for normal data and "stderr" for the rest (status messages, etc...). Piping usually only deals with the first one. – xenoid Sep 7 at 13:53
  • Could you please edit your question and clarify what you are asking? I can't understand what the actual question is. It feels like you have (at least) two separate issues: one is about how the output streams work and another is about how ffmpeg works. I suspect that most of your confusion is about the difference between stdout and stderr, but I can't really tell since your mention of ffmpeg and vlc is clouding the waters. Could you please edit and simplify this to one, specific question? – terdon Sep 7 at 13:54
  • 1
  • @terdon That's a great discussion, thanks. I spent quite a lot of time searching and didn't uncover that one. – McGuireV10 Sep 7 at 14:04
  • Command output that would be useful as input for other commands is usually sent to stdout while debug/status/progress/errors and such things are usually sent to stderr – svin83 Sep 7 at 14:05

There are two different approaches for a program to send output that is separate from its standard output.

One is to output to standard error, and as you suspect, this might be more common on Unix-style environments than on Windows; see Do progress reports/logging information belong on stderr or stdout? for some discussion of this. Standard error can be redirected; see What are the shell's control and redirection operators?

The other is to output directly to the terminal the program is running on, if any, by using /dev/tty. See How does `less` take data from stdin while still be able to read commands from user? for a discussion of this (on input, but similar aspects apply to output).

| improve this answer | |
  • Bonus points for the /dev/tty trick, neat. Thanks! – McGuireV10 Sep 7 at 14:03

stderr and stdout are the default ways to output text to a terminal.

Function using echo and redirection to output to both stderr and stdout:

function multioutput(){
 >&2 echo 'stderr output'
 echo 'stdout output'

To redirect ffmpeg stderr into stdout, so both are piped to vlc stdin:

2>&1 ffmpeg -arg1 -arg2|vlc

What vlc would do with the text output from other commands is beyond me though...

If you explained your goal I might have had better luck trying to help you...

| improve this answer | |
  • My goal here was understanding the *nix way this works, but what I'm actually having trouble with is over on StackOverflow here – McGuireV10 Sep 7 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.