The standard output stream (stdout) is the stream where a program writes its output data.
Questions tagged [stdout]
4740 questions
75
votes
9 answers
Temporarily Redirect stdout/stderr
Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?
Edit:
The problem with the current solutions (which I at first remembered but then forgot) is that they don't redirect; rather, they just replace the…

user541686
- 205,094
- 128
- 528
- 886
75
votes
10 answers
log4j redirect stdout to DailyRollingFileAppender
I have a java app that uses log4j.
Config:
log4j.rootLogger=info,…

letronje
- 9,002
- 9
- 45
- 53
74
votes
7 answers
How to capture stdout/stderr with googletest?
Is it possible to capture the stdout and stderr when using the googletest framework?
For example, I would like to call a function that writes errors to the console (stderr).
Now, when calling the function in the tests, I want to assert that no…

Jan Rüegg
- 9,587
- 8
- 63
- 105
74
votes
10 answers
How to write stdout to file with colors?
A lot of times (not always) the stdout is displayed in colors. Normally I keep every output log in a different file too. Naturally in the file, the colors are not displayed anymore.
I'd like to know if there's a way (in Linux) to write the output…

AAlvz
- 1,059
- 2
- 9
- 15
74
votes
7 answers
C++ alignment when printing cout <<
Is there a way to align text when printing using std::cout? I'm using tabs, but when the words are too big they won't be aligned anymore.
Sales Report for September 15, 2010
Artist Title Price Genre Disc Sale Tax Cash
Merle Blue …

user69514
- 26,935
- 59
- 154
- 188
72
votes
6 answers
redirect stdout/stderr to a string
there has been many previous questions about redirecting stdout/stderr to a file. is there a way to redirect stdout/stderr to a string?

Prasanth Madhavan
- 12,657
- 15
- 62
- 94
72
votes
4 answers
How to have an in-place string that updates on stdout
I want to output to stdout and have the output "overwrite" the previous output.
For example; if I output On 1/10, I want the next output On 2/10 to overwrite On 1/10. How can I do this?
user1529891
69
votes
2 answers
Update Command-line Output, i.e. for Progress
I'd like to be able to show a progress meter in a simple PHP script on the command line. Instead of seeing
Progress: 0%
Progress: 1%
etc...
I'd like just the number to change, and replace the previous number, much like git clone does for example…

Adam
- 5,091
- 5
- 32
- 49
67
votes
3 answers
How can I redirect STDERR to STDOUT, but ignore the original STDOUT?
I have a program whose STDERR output I want to inspect and run grep on etc.
So I could redirect it to STDOUT and use grep, but the problem is, I do not want the original STDOUT content.
So, this one won't do
cmd 2>&1 | grep pattern
because it will…

Frank
- 64,140
- 93
- 237
- 324
67
votes
5 answers
In Go, how do I capture stdout of a function into a string?
In Python, for example, I can do the following:
realout = sys.stdout
sys.stdout = StringIO.StringIO()
some_function() # prints to stdout get captured in the StringIO object
result = sys.stdout.getvalue()
sys.stdout = realout
Can you do this in Go?

Andres Riofrio
- 9,851
- 7
- 40
- 60
66
votes
4 answers
Bash script - store stderr in a variable
I'm writing a script to backup a database. I have the following line:
mysqldump --user=$dbuser --password=$dbpswd \
--host=$host $mysqldb | gzip > $filename
I want to assign the stderr to a variable, so that it will send an email to myself…

thornate
- 4,902
- 9
- 39
- 43
66
votes
6 answers
Capture both stdout and stderr in Bash
I know this syntax
var=`myscript.sh`
or
var=$(myscript.sh)
Will capture the result (stdout) of myscript.sh into var. I could redirect stderr into stdout if I wanted to capture both. How to save each of them to separate variables?
My use case here…

djechlin
- 59,258
- 35
- 162
- 290
63
votes
8 answers
how to redirect STDOUT to a file in PHP?
The code below almost works, but it's not what I really meant:
ob_start();
echo 'xxx';
$contents = ob_get_contents();
ob_end_clean();
file_put_contents($file,$contents);
Is there a more natural way?

omg
- 136,412
- 142
- 288
- 348
63
votes
7 answers
Python read from subprocess stdout and stderr separately while preserving order
I have a python subprocess that I'm trying to read output and error streams from. Currently I have it working, but I'm only able to read from stderr after I've finished reading from stdout. Here's what it looks like:
process =…

Leah Sapan
- 3,621
- 7
- 33
- 57
61
votes
4 answers
Call another click command from a click command
I want to use some useful functions as commands. For that I am testing the click library. I defined my three original functions then decorated as click.command:
import click
import os, sys
@click.command()
@click.argument('content',…

kaligne
- 3,098
- 9
- 34
- 60