The standard output stream (stdout) is the stream where a program writes its output data.
Questions tagged [stdout]
4740 questions
111
votes
13 answers
catching stdout in realtime from subprocess
I want to subprocess.Popen() rsync.exe in Windows, and print the stdout in Python.
My code works, but it doesn't catch the progress until a file transfer is done! I want to print the progress for each file in real time.
Using Python 3.1 now since I…

John A
- 1,111
- 2
- 8
- 4
104
votes
3 answers
Difference between $stdout and STDOUT in Ruby
In Ruby, what is the difference between $stdout (preceded by a dollar sign) and STDOUT (in all caps)? When doing output redirection, which should be used and why? The same goes for $stderr and STDERR.
Edit: Just found a related question.

jrdioko
- 32,230
- 28
- 81
- 120
99
votes
8 answers
How to get Rails.logger printing to the console/stdout when running rspec?
Same as title: How to get Rails.logger printing to the console/stdout when running rspec? Eg.
Rails.logger.info "I WANT this to go to console/stdout when rspec is running"
puts "Like how the puts function works"
I still want Rails.logger to go to…

s12chung
- 1,718
- 1
- 14
- 29
98
votes
5 answers
How to make output of any shell command unbuffered?
Is there a way to run shell commands without output buffering?
For example, hexdump file | ./my_script will only pass input from hexdump to my_script in buffered chunks, not line by line.
Actually I want to know a general solution how to make any…

bodacydo
- 75,521
- 93
- 229
- 319
91
votes
6 answers
Continuously read from STDOUT of external process in Ruby
I want to run blender from the command line through a ruby script, which will then process the output given by blender line by line to update a progress bar in a GUI. It's not really important that blender is the external process whose stdout I need…

ehsanul
- 7,737
- 7
- 33
- 43
90
votes
4 answers
How do file descriptors work?
Can someone tell me why this does not work? I'm playing around with file descriptors, but feel a little lost.
#!/bin/bash
echo "This"
echo "is" >&2
echo "a" >&3
echo "test." >&4
The first three lines run fine, but the last two error out. Why?

Trcx
- 4,164
- 6
- 30
- 30
87
votes
7 answers
How do I check if stdin has some data?
In Python, how do you check if sys.stdin has data or not?
I found that os.isatty(0) can not only check if stdin is connected to a TTY device, but also if there is data available.
But if someone uses code such as
sys.stdin =…

mlzboy
- 14,343
- 23
- 76
- 97
87
votes
8 answers
How to replicate tee behavior in Python when using subprocess?
I'm looking for a Python solution that will allow me to save the output of a command in a file without hiding it from the console.
FYI: I'm asking about tee (as the Unix command line utility) and not the function with the same name from Python…

sorin
- 161,544
- 178
- 535
- 806
87
votes
10 answers
How to redirect stdout and stderr to logger in Python
I have a logger that has a RotatingFileHandler.
I want to redirect all Stdout and Stderr to the logger.
How to do so?

orenma
- 1,163
- 2
- 10
- 19
85
votes
1 answer
How to write CSV output to stdout?
I know I can write a CSV file with something like:
with open('some.csv', 'w', newline='') as f:
How would I instead write that output to stdout?

jsf80238
- 1,577
- 2
- 11
- 24
84
votes
5 answers
Gradle: How to get output from test STDERR/STDOUT into console?
(Gradle 3.2.1) I run some java tests, which logs output in Stderr/Stdout. I can see that output, if I start
gradle test --info
but in that case, much of unwanted output from 3-rd party libraries is there too.
Documentation suggests using…

Alexei Vinogradov
- 1,548
- 3
- 15
- 34
82
votes
5 answers
Redirect console output to string in Java
I have one method whose return type is void and it prints directly on console.
However I need that output in a String so that I can work on it.
As I can't make any changes to the method with return type void I have to redirect that output to a…

SRK
- 1,020
- 1
- 9
- 11
82
votes
7 answers
How to set sys.stdout encoding in Python 3?
Setting the default output encoding in Python 2 is a well-known idiom:
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
This wraps the sys.stdout object in a codec writer that encodes output in UTF-8.
However, this technique does not work in…

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
81
votes
1 answer
The difference between stdout and STDOUT_FILENO
I was wondering the difference between stdout and STDOUT_FILENO in Linux C.
After some searching work, I draw the following conclusion. Could you help me review it and correct any mistake in it? Thanks
stdout belongs to standard I/O stream of C…

Bing Lu
- 3,232
- 7
- 30
- 38
78
votes
8 answers
Silence the stdout of a function in Python without trashing sys.stdout and restoring each function call
Is there a way in Python to silence stdout without wrapping a function call like following?
Original Broken Code:
from sys import stdout
from copy import copy
save_stdout = copy(stdout)
stdout = open('trash','w')
foo()
stdout = save_stdout
Edit:…

Tim McJilton
- 6,884
- 6
- 25
- 27