The standard output stream (stdout) is the stream where a program writes its output data.
Questions tagged [stdout]
4740 questions
262
votes
16 answers
Reusing output from last command in Bash
Is the output of a Bash command stored in any register? E.g. something similar to $? capturing the output instead of the exit status.
I could assign the output to a variable with:
output=$(command)
but that's more typing...

memecs
- 7,196
- 7
- 34
- 49
262
votes
10 answers
How to redirect the output of a PowerShell to a file during its execution
I have a PowerShell script for which I would like to redirect the output to a file. The problem is that I cannot change the way this script is called. So I cannot do:
.\MyScript.ps1 > output.txt
How do I redirect the output of a PowerShell script…

Martin
- 39,309
- 62
- 192
- 278
233
votes
3 answers
Piping both stdout and stderr in bash?
It seems that newer versions of bash have the &> operator, which (if I understand correctly), redirects both stdout and stderr to a file (&>> appends to the file instead, as Adrian clarified).
What's the simplest way to achieve the same thing, but…

Andrew Ferrier
- 16,664
- 13
- 47
- 76
212
votes
22 answers
How to disable logging on the standard error stream?
How to disable logging on the standard error stream in Python? This does not work:
import logging
logger = logging.getLogger()
logger.removeHandler(sys.stderr)
logger.warning('foobar') # emits 'foobar' on sys.stderr

sorin
- 161,544
- 178
- 535
- 806
206
votes
8 answers
How to open every file in a folder
I have a python script parse.py, which in the script open a file, say file1, and then do something maybe print out the total number of characters.
filename = 'file1'
f = open(filename, 'r')
content = f.read()
print filename, len(content)
Right…

B.Mr.W.
- 18,910
- 35
- 114
- 178
202
votes
6 answers
Why is printing to stdout so slow? Can it be sped up?
I've always been amazed/frustrated with how long it takes to simply output to the terminal with a print statement. After some recent painfully slow logging I decided to look into it and was quite surprised to find that almost all the time spent is…

Russ
- 10,835
- 12
- 42
- 57
187
votes
5 answers
How to capture stdout output from a Python function call?
I'm using a Python library that does something to an object
do_something(my_object)
and changes it. While doing so, it prints some statistics to stdout, and I'd like to get a grip on this information. The proper solution would be to change…

Nico Schlömer
- 53,797
- 27
- 201
- 249
182
votes
9 answers
Can I redirect the stdout into some sort of string buffer?
I'm using python's ftplib to write a small FTP client, but some of the functions in the package don't return string output, but print to stdout. I want to redirect stdout to an object which I'll be able to read the output from.
I know stdout can be…

Avihu Turzion
- 3,284
- 4
- 25
- 34
169
votes
7 answers
Force line-buffering of stdout in a pipeline
Usually, stdout is line-buffered. In other words, as long as your printf argument ends with a newline, you can expect the line to be printed instantly. This does not appear to hold when using a pipe to redirect to tee.
I have a C++ program, a, that…

houbysoft
- 32,532
- 24
- 103
- 156
141
votes
6 answers
Redirect all output to file using Bash on Linux?
I am trying to redirect all output from a command line programme to a file. I am using Bash. Some of the output is directed to a the file, but some still appears in the terminal and is not stored to the file.
Similar symptoms are described…

Stefan
- 8,819
- 10
- 42
- 68
137
votes
6 answers
Python: How to get stdout after running os.system?
I want to get the stdout in a variable after running the os.system call.
Lets take this line as an example:
batcmd="dir"
result = os.system(batcmd)
result will contain the error code (stderr 0 under Windows or 1 under some linux for the above…

Eduard Florinescu
- 16,747
- 28
- 113
- 179
127
votes
12 answers
How can I log the stdout of a process started by start-stop-daemon?
I am using an init script to run a simple process, which is started with:
start-stop-daemon --start --quiet --chuid $DAEMONUSER \
--make-pidfile --pidfile $PIDFILE --background \
--exec $DAEMON $DAEMON_ARGS
The process called…

joeytwiddle
- 29,306
- 13
- 121
- 110
121
votes
12 answers
Capture stdout from a script?
suppose there is a script doing something like this:
# module writer.py
import sys
def write():
sys.stdout.write("foobar")
Now suppose I want to capture the output of the write function and store it in a variable for further processing. The…

Paolo
- 20,112
- 21
- 72
- 113
116
votes
3 answers
Redirect stdout pipe of child process in Go
I'm writing a program in Go that executes a server like program (also Go). Now I want to have the stdout of the child program in my terminal window where I started the parent program. One way to do this is with the cmd.Output() function, but this…

mbert
- 1,495
- 2
- 11
- 17
115
votes
19 answers
Print to the same line and not a new line?
Basically I want to do the opposite of what this guy did... hehe.
Python Script: Print new line each time to shell rather than update existing line
I have a program that is telling me how far along it is.
for i in some_list:
#do a bunch of…

chriscauley
- 19,015
- 9
- 33
- 33