Questions tagged [stderr]

Standard error is another output stream typically used by programs to output error messages or diagnostics.

Filter by
Sorted by
Tagged with
87
votes
5answers
7k views

Do progress reports/logging information belong on stderr or stdout?

Is there an official POSIX, GNU, or other guideline on where progress reports and logging information (things like "Doing foo; foo done") should be printed? Personally, I tend to write them to stderr ...
68
votes
6answers
15k views

Can I configure my shell to print STDERR and STDOUT in different colors?

I want to set my terminal up so stderr is printed in a different color than stdout; maybe red. This would make it easier to tell the two apart. Is there a way to configure this in .bashrc? If not, is ...
58
votes
2answers
117k views

suppress stderr messages in a bash script

Consider the following (slightly silly) script name 'test1.sh': #/bin/bash # sleep 10 & echo sleep pid = $! pkill sleep When I run it, I get not only the output of the echo, but bash's reporting ...
34
votes
4answers
62k views

X applications warn “Couldn't connect to accessibility bus:” on stderr

It seems like every application from the terminal gives warnings and error messages, even though it appears to run fine. Emacs: ** (emacs:5004): WARNING **: Couldn't connect to accessibility bus: ...
33
votes
5answers
6k views

How to redirect stdout to a file, and stdout+stderr to another one?

How can I achieve cmd >> file1 2>&1 1>>file2 That is, the stdout and stderr should redirect to one file (file1) and only stdout (file2) should redirect to another (both in append ...
27
votes
3answers
2k views

Is it safe to redirect stdout and stderr to the same file without file descriptor copies?

I start off in empty directory. $ touch aFile $ ls aFile Then I ls two arguments, one of which isn't in this directory. I redirect both output streams to a file named output. I use >> in order ...
23
votes
3answers
91k views

nohup: ignoring input and redirecting stderr to stdout

I am starting my application in the background using nohup as mentioned below - root@phx5qa01c:/bezook# nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --...
19
votes
2answers
13k views

Does `Segmentation fault` message come under STDERR?

I ran an executable in bash ./code > log It shows occasional error messages on terminal whereas all printf statements go into log file. I re-run it like below ./code >& log Now, the ...
19
votes
1answer
8k views

How can I pipe only stderr in zsh?

In bash: $ echo hi 2>&1 1>/dev/null | cat $ While in zsh: $ echo hi 2>&1 1>/dev/null | cat hi $ Is there a way to pipe only standard error while redirecting standard out?
17
votes
2answers
2k views

What prevents stdout/stderr from interleaving?

Say I run some processes: #!/usr/bin/env bash foo & bar & baz & wait; I run the above script like so: foobarbaz | cat as far as I can tell, when any of the processes write to stdout/...
16
votes
1answer
4k views

Output of command not in stderr nor stdout

I've stumbled on this issue, so I'm wondering how is this possible? Standard run of command: # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 info from server: "Processed 0 Failed 1 ...
15
votes
3answers
2k views

When to use redirection to stderr in shell scripts

I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr. $ grep '^foo' file1 file2 file1:foo grep: file2: No such file or directory When I'm ...
14
votes
2answers
2k views

Unix systems without /dev/stdin, /dev/stdout, and /dev/stderr? [duplicate]

An answer I gave to a question, and the comments to it, had me read the POSIX Conformance section of the Base Definitions to figure out whether /dev/stdin, /dev/stdout and /dev/stderr were actually ...
13
votes
2answers
599 views

Should I output program's name when warning or error occurs?

If I'm writing a script or a program, should I output to stderr its name together with warning or error message? For example: ./script.sh: Warning! Variable "var" lowered down to 10. or: ./prog.py: ...
12
votes
4answers
19k views

Copy stdout and stderr to a log file and leave them on the console within the script itself [duplicate]

Using bash, how do I copy stderr and stdout to a log file and also leave them displayed on the console? I would like to do this within the script itself using an exec. I tried with exec &>&...
12
votes
2answers
1k views

How (and why) use stderr for both reading and writing?

According to this answer by schily, less reads navigation commands from stderr if it's not able to open /dev/tty. This seems puzzling, since I've never seen anything write to another program's stderr ...
11
votes
3answers
959 views

what is the difference between `>> /dev/stderr` (with the white space) and `>&2`?

In bash. I am having some difficulty to determine what I should use? all my scripts use ">>/dev/stderr" at bash prompt, if I try: echo test >>/dev/stderr works echo test >> /dev/stderr ...
11
votes
3answers
7k views

sending output to /dev/stderr vs. >&2

In scripts, errors are usually sent to file descriptor 2 with &2, ie: echo "error" >&2 Sometimes /dev/stderr is used instead: echo "error" > /dev/stderr Looking at /dev/stderr, I ...
11
votes
1answer
455 views

Why can issuing the same command create more output in tty than in pts/gnome-terminal?

gnome-terminal: $ sudo update-grub [sudo] password for user: Generating grub configuration file ... Found background image: .background_cache.png Found linux image: /boot/vmlinuz-3.16.0-4-amd64 ...
11
votes
2answers
10k views

stderr over ssh -t

This sends output to STDERR, but does not propagate Ctrl+C (i.e. Ctrl+C will kill ssh but not the remote sleep): $ ssh localhost 'sleep 100;echo foo ">&2"' This propagates Ctrl+C (i.e. Ctrl+C ...
10
votes
1answer
2k views

POSIX compliant way to redirect stdout and stderr to a file [duplicate]

I am trying to write a script which is POSIX compliant, so it can run on any *nix system (Debian, Fedora, CentOS, AIX, Arch... ALL of them). When it comes to redirection, I am rather confused on what ...
10
votes
2answers
1k views

When to use standard error stream in command-line application?

Is there a guideline when to use the error when writing a command-line application? To my surprise, I didn't find anything when googling it. In particular, the question I'm concerned with right now ...
10
votes
1answer
4k views

`docker logs foo | less` isn't searchable or scrollable but `docker logs foo 2>&1 | less` is

Using either one gives readable text. But only with the stderr redirect can one scroll or type /somepattern and get matches. Without it searching gives "Nothing to search (press RETURN)" and a ...
9
votes
2answers
24k views

How can I filter those “Permission denied” from find output? [duplicate]

I started using sed recently. One handy way I use it is to ignore unimportant lines of a log file: tail -f example.com-access.log | sed '/127.0.0.1/d;/ELB-/d;/408 0 "-" "-"/d;' But when I try to use ...
9
votes
1answer
1k views

display STDOUTs before STDERR?

I'm new to bash and I can not for the life of me figure out how to run a certain command, suppose ./fff and print regular stdouts before stderr (I'm confused about the meaning myself) for example $ ...
8
votes
2answers
9k views

Inconsistency of stderr redirection between tcsh and other shells

I'm running into issues with redirection in tcsh. Consider the following commands: vi --version and vi --xxx. And let's assume this is on a machine where vi supports the --version option. The ...
8
votes
4answers
2k views

A command that generates both standard error and output

I want to do some troubleshooting on my bash script. Is there a short and simple command that generates both stdout and stderr so that I can use 2>&1 on it? Sorry if this looks trivial, but I ...
8
votes
1answer
649 views

Can redirecting stdout and stderr to the same file mangle lines?

I've read that when redirecting stdout and stderr to the same file using 2>&1, stdout is usually block buffered while stderr is unbuffered. If a very long line is written to stdout, requiring ...
7
votes
3answers
23k views

stdin, stderr, redirection and logs

Is there a difference between those two lines ? /home/user/script.sh >> /home/user/stdout_and_error.log 2>&1 /home/user/script.sh 2>&1 >> /home/user/stdout_and_error.log ...
7
votes
3answers
2k views

How to run a command while logging output to a file?

I have a console application that needs to be run as part of the deployment of a new application version on my server. This console application is designed to output to the console, and cannot be ...
7
votes
1answer
17k views

How do I get the output of a cron script run from my home directory?

I'm using Amazon Linux and trying to run a cron job from my home directory (I don't have sudo permissions on the machine). I'm setting a cron job by executing crontab -e and adding this line 30 18 * ...
7
votes
2answers
945 views

Why does bash interactive shell by default write its prompt and echoes its interactive input to stderr?

I just noticed that bash interactive shell by default writes the prompt and echoes anything you type to file descriptor 2 (stderr). This can be verified by running bash inside strace. What is the ...
7
votes
2answers
2k views

Redirecting standard error output to bash variable

Here's a C code snippet that will cause segfault: // segfault.c #include <string.h> int main() { memset((char *)0x0, 1, 100); return 1; } Compile it with: gcc segfault.c -o segfault ...
7
votes
2answers
691 views

To which stream does xsel print the no newline warning?

xsel is a program with which you can access system clipboard from command line. If there is no newline at the end of copied content, it prints a warning after the clipboard content like this: $ xsel -...
6
votes
3answers
3k views

Communicate backwards in a pipe

I have a simple pipeline: node foo.js | node bar.js bar.js will read from stdin to get data from foo.js. But what I want to do is ensure that bar.js gets one of the last messages from foo.js before ...
6
votes
4answers
20k views

Write to stderr

I'm using stderred to color all output streamed to stderr red. It's working fine. But when I write my own bash script and throw an error with echo 'error' 1>&2, it doesn't color the output in ...
6
votes
1answer
497 views

Is it possible to create sticky redirection from stdout/stderr

Consider such code: echo hello >> log.txt echo world >> log.txt I execute command with stdout redirection. Is it possible to create sticky redirection? Something like this: redir stdout ...
6
votes
3answers
5k views

Redirect STDERR and STDOUT to different variables without temporary files

func() { echo 'hello' echo 'This is an error' >&2 } a=$(func) b=??? I'd like to redirect the stderr to b variable without creating a temporary file. echo $b # output should be: "...
6
votes
1answer
2k views

/dev/stderr in systemd service

I'm writing a service which should start LTE connection. But the utility I'm using to connect (sakis3g) is writing to /dev/stderr, which is not available in systemd and the log is full of Cannot ...
6
votes
1answer
1k views

Redirect bash stdout+stderr to one file and stderr to another file

I need to redirect ALL output to one file, and in addition redirect stderr to another file. Can this be done easily? Let's assume my command for the purposes of this example is: php /tmp/doWork.php ...
5
votes
3answers
608 views

How can I use sed to edit bash debug output? (bash -x)

#!/bin/bash -x echo This is a script that has debugging turned on This script outputs + echo This is a script that has debugging turned on This is a script that has debugging turned on I want to ...
5
votes
2answers
2k views

Why can't I get pgrep output right to variable on bash script?

I'm trying to make a script to either quit compton if it's running or start it if it's not running. I've read from man that it should exit 1 if process is found, so I've tried to make a script that ...
5
votes
3answers
264 views

Trying to make sense of bash redirection syntaxes and their outputs

I'm new to Linux and trying to understand how redirections work. I have been testing various syntaxes for redirecting stdout and stderr to the same file, which don't all produce the same results. ...
5
votes
4answers
5k views

How to redirect stderr in a variable but keep stdout in the console [duplicate]

My goal is to call a command, get stderr in a variable, but keep stdout (and only stdout) on the screen. Yep, that's the opposite of what most people do :) For the moment, the best I have is : #!/...
5
votes
2answers
18k views

where is the location of stdin, stdout, stderr file descriptor in AIX(unix)

In my Linux environment, the file descriptors are located on /dev/fd. Where is the location of stdin, stdout, stderr file descriptor in AIX(unix). I couldn't find them.
5
votes
2answers
39k views

How to redirect error to a file?

I have this simple script which redirects the output and append it to a file. filename="/home/ronnie/tmp/hello" date=$(date) echo "$date" >> $filename Now, lets suppose I change date=$(date) ...
5
votes
1answer
12k views

what is the difference between >&2 and &>2 [duplicate]

Just wondering if there is any difference between: echo "running the npm patch" >&2; and echo "running the npm patch" &>2; I have actually never really understand that syntax.
5
votes
2answers
3k views

Is there a simple test for anything printed on stderr in shell/Bash?

I'd like invoke a command inside a shell script for Continuous Integration purposes. Exit status 0 means succes, otherwise failure. I'm writing a wrapper script to run several commands and fail if any ...
5
votes
1answer
224 views

How to create a real copy of file descriptor stdout and stderr without using unbuffer / script / tee just with bash built-ins?

My goal is to duplicate, redirect all output (stdout and stderr) of an application (apt-get) to a file while retaining the usual behavior of the application (apt-get), stdout and stderr. How to ...
4
votes
1answer
279 views

stdout and stderr redirection to different files

How can I redirect stdout to 2 different files and stderr to another, different file? I want something like <my_cmd> 1> file1 file2 2>file3 I know: <my_cmd> | tee file1 file2 > /...