How does a program output to a terminal when stdout is piped?

McGuireV10

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...

Stephen Kitt

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Program output changes when piped

From Dev

How does a Unix program know to change output if it's being piped?

From Dev

How does a program know if stdout is connected to a terminal or a pipe?

From Dev

How to output piped stdout in bash script from getopts?

From Dev

ag output appears different in the terminal vs when piped to a file

From Dev

Why won't journalctl show logs when the program output is piped?

From Dev

How does/frequent unix tee command write stdout terminal output to file? if the output is too big

From Dev

When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

From Dev

When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

From Dev

Why does bash output data instead of executing, when a script is piped?

From Dev

Send find's output to stdout and piped to grep

From Dev

How can processes eliminate escape codes when its output is piped?

From Dev

How can a Unix program display output on screen even when stdout and stderr are redirected?

From Dev

In what format does piped output get sent and received from one command/program to another?

From Dev

How do I tell if a program is printing to stderr or stdout in the terminal?

From Dev

How to generate sql output as piped

From Dev

How is stdout piped in to a file located in a different directory?

From Dev

When does piped command stop?

From Dev

How do I pipe terminal standard output (stdout) to the clipboard?

From Dev

How do I pipe terminal standard output (stdout) to the clipboard?

From Dev

Output piped content to file and show number of lines in the file on stdout

From Dev

Ping piped to txt does output nothing

From Dev

Why does `cd` have no effect if output is piped?

From Dev

why does the output of `ls` look different when piped through ``tr "\n" "\n"`?

From Dev

stdout of spawned process works strange when being piped

From Dev

stdout of spawned process works strange when being piped

From Dev

How to hide terminal output when executing a command?

From Dev

How to hide terminal output when executing a command?

From Dev

How to format piped output in powershell to a line

Related Related

  1. 1

    Program output changes when piped

  2. 2

    How does a Unix program know to change output if it's being piped?

  3. 3

    How does a program know if stdout is connected to a terminal or a pipe?

  4. 4

    How to output piped stdout in bash script from getopts?

  5. 5

    ag output appears different in the terminal vs when piped to a file

  6. 6

    Why won't journalctl show logs when the program output is piped?

  7. 7

    How does/frequent unix tee command write stdout terminal output to file? if the output is too big

  8. 8

    When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

  9. 9

    When stdout is being used to output binary data, how can I also output debug/verbose info to the terminal?

  10. 10

    Why does bash output data instead of executing, when a script is piped?

  11. 11

    Send find's output to stdout and piped to grep

  12. 12

    How can processes eliminate escape codes when its output is piped?

  13. 13

    How can a Unix program display output on screen even when stdout and stderr are redirected?

  14. 14

    In what format does piped output get sent and received from one command/program to another?

  15. 15

    How do I tell if a program is printing to stderr or stdout in the terminal?

  16. 16

    How to generate sql output as piped

  17. 17

    How is stdout piped in to a file located in a different directory?

  18. 18

    When does piped command stop?

  19. 19

    How do I pipe terminal standard output (stdout) to the clipboard?

  20. 20

    How do I pipe terminal standard output (stdout) to the clipboard?

  21. 21

    Output piped content to file and show number of lines in the file on stdout

  22. 22

    Ping piped to txt does output nothing

  23. 23

    Why does `cd` have no effect if output is piped?

  24. 24

    why does the output of `ls` look different when piped through ``tr "\n" "\n"`?

  25. 25

    stdout of spawned process works strange when being piped

  26. 26

    stdout of spawned process works strange when being piped

  27. 27

    How to hide terminal output when executing a command?

  28. 28

    How to hide terminal output when executing a command?

  29. 29

    How to format piped output in powershell to a line

HotTag

Archive