Pipe stderr only if a terminal application crashes The 2019 Stack Overflow Developer Survey...

Manuscript was "unsubmitted" because the manuscript was deposited in Arxiv Preprints

What is the use of option -o in the useradd command?

What can other administrators access on my machine?

Return to UK after being refused

How was Skylab's orbit inclination chosen?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

How to deal with fear of taking dependencies

How do you say "canon" as in "official for a story universe"?

How can I fix this gap between bookcases I made?

Pristine Bit Checking

How to change the limits of integration

Why is it "Tumoren" and not "Tumore"?

Is flight data recorder erased after every flight?

How are circuits which use complex ICs normally simulated?

Understanding the implication of what "well-defined" means for the operation in quotient group

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

Why isn't airport relocation done gradually?

Dual Citizen. Exited the US on Italian passport recently

How is radar separation assured between primary and secondary targets?

Unbreakable Formation vs. Cry of the Carnarium

Idiomatic way to prevent slicing?

Patience, young "Padovan"

Are there any other methods to apply to solving simultaneous equations?

Does duplicating a spell with Wish count as casting that spell?



Pipe stderr only if a terminal application crashes



The 2019 Stack Overflow Developer Survey Results Are InRedirect stderr from an already running scriptRedirect stdout and stderr, with timestamps on stderr onlyHow to strip color codes out of stdout and pipe to file and stdoutHow to capture ordered STDOUT/STDERR and add timestamp/prefixes?A way to distinguish between interleaved output from two background processesBash interactive mode on redirectWhy is /dev/stderr invalid when redirecting to a pipe in cygwin?Send stderr to a different receiver in pipeDetermine if process was launched directly from a terminal window or programmatically as a child processUsing pipe STDOUT as a variable?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I have a program which interacts with the user on the terminal.



But if it crashes I'd like to pipe the stderr through another tool to tidy / prettyprint it.



Is there a way to do this?



As far as I can see, the ways of redirecting the stderr all involve doing something with stdout, and that hides / disrupts the interactive terminal.










share|improve this question























  • Are you asking about the pretty printing, or about how to arrange for that other tool to get the error output, or both?

    – Kusalananda
    yesterday













  • What I really want right now is the pretty-printing what comes out on stderr if the interactive program crashes. I thought this would be the general case that would also solve that. But I'm open to other solutions

    – interstar
    14 hours ago






  • 1





    Are you able to get the program to do logging to a file, i.e. from the program itself?

    – Kusalananda
    13 hours ago











  • Not simply. If this can't be done, then it can't be done, and I'll have to look for another solution. Exactly explicitly trying to intercept errors etc. I was just hoping there was some command-line / pipeline magic that could solve it.

    – interstar
    12 hours ago


















1















I have a program which interacts with the user on the terminal.



But if it crashes I'd like to pipe the stderr through another tool to tidy / prettyprint it.



Is there a way to do this?



As far as I can see, the ways of redirecting the stderr all involve doing something with stdout, and that hides / disrupts the interactive terminal.










share|improve this question























  • Are you asking about the pretty printing, or about how to arrange for that other tool to get the error output, or both?

    – Kusalananda
    yesterday













  • What I really want right now is the pretty-printing what comes out on stderr if the interactive program crashes. I thought this would be the general case that would also solve that. But I'm open to other solutions

    – interstar
    14 hours ago






  • 1





    Are you able to get the program to do logging to a file, i.e. from the program itself?

    – Kusalananda
    13 hours ago











  • Not simply. If this can't be done, then it can't be done, and I'll have to look for another solution. Exactly explicitly trying to intercept errors etc. I was just hoping there was some command-line / pipeline magic that could solve it.

    – interstar
    12 hours ago














1












1








1


0






I have a program which interacts with the user on the terminal.



But if it crashes I'd like to pipe the stderr through another tool to tidy / prettyprint it.



Is there a way to do this?



As far as I can see, the ways of redirecting the stderr all involve doing something with stdout, and that hides / disrupts the interactive terminal.










share|improve this question














I have a program which interacts with the user on the terminal.



But if it crashes I'd like to pipe the stderr through another tool to tidy / prettyprint it.



Is there a way to do this?



As far as I can see, the ways of redirecting the stderr all involve doing something with stdout, and that hides / disrupts the interactive terminal.







bash pipe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









interstarinterstar

3621821




3621821













  • Are you asking about the pretty printing, or about how to arrange for that other tool to get the error output, or both?

    – Kusalananda
    yesterday













  • What I really want right now is the pretty-printing what comes out on stderr if the interactive program crashes. I thought this would be the general case that would also solve that. But I'm open to other solutions

    – interstar
    14 hours ago






  • 1





    Are you able to get the program to do logging to a file, i.e. from the program itself?

    – Kusalananda
    13 hours ago











  • Not simply. If this can't be done, then it can't be done, and I'll have to look for another solution. Exactly explicitly trying to intercept errors etc. I was just hoping there was some command-line / pipeline magic that could solve it.

    – interstar
    12 hours ago



















  • Are you asking about the pretty printing, or about how to arrange for that other tool to get the error output, or both?

    – Kusalananda
    yesterday













  • What I really want right now is the pretty-printing what comes out on stderr if the interactive program crashes. I thought this would be the general case that would also solve that. But I'm open to other solutions

    – interstar
    14 hours ago






  • 1





    Are you able to get the program to do logging to a file, i.e. from the program itself?

    – Kusalananda
    13 hours ago











  • Not simply. If this can't be done, then it can't be done, and I'll have to look for another solution. Exactly explicitly trying to intercept errors etc. I was just hoping there was some command-line / pipeline magic that could solve it.

    – interstar
    12 hours ago

















Are you asking about the pretty printing, or about how to arrange for that other tool to get the error output, or both?

– Kusalananda
yesterday







Are you asking about the pretty printing, or about how to arrange for that other tool to get the error output, or both?

– Kusalananda
yesterday















What I really want right now is the pretty-printing what comes out on stderr if the interactive program crashes. I thought this would be the general case that would also solve that. But I'm open to other solutions

– interstar
14 hours ago





What I really want right now is the pretty-printing what comes out on stderr if the interactive program crashes. I thought this would be the general case that would also solve that. But I'm open to other solutions

– interstar
14 hours ago




1




1





Are you able to get the program to do logging to a file, i.e. from the program itself?

– Kusalananda
13 hours ago





Are you able to get the program to do logging to a file, i.e. from the program itself?

– Kusalananda
13 hours ago













Not simply. If this can't be done, then it can't be done, and I'll have to look for another solution. Exactly explicitly trying to intercept errors etc. I was just hoping there was some command-line / pipeline magic that could solve it.

– interstar
12 hours ago





Not simply. If this can't be done, then it can't be done, and I'll have to look for another solution. Exactly explicitly trying to intercept errors etc. I was just hoping there was some command-line / pipeline magic that could solve it.

– interstar
12 hours ago










1 Answer
1






active

oldest

votes


















0














You might have to wrap the program in a small bash script, but it's doable. You can redirect stderr to a file while leaving stdout to display on the screen:



#!/usr/bin/env bash

# Run my program, with stderr saved to a file
my_program 2> /tmp/stderr_output.txt

# If the program returned with anything but success, print stderr
if [ ! $! ]; then
cat /tmp/stderr_output.txt
fi


Instead of just using the cat utility, you could use your formatting utility to output the error text.






share|improve this answer



















  • 4





    $! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

    – Kusalananda
    yesterday













  • Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

    – interstar
    14 hours ago






  • 1





    @interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

    – Kusalananda
    13 hours ago











  • So basically, can't be done then?

    – interstar
    13 hours ago












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511351%2fpipe-stderr-only-if-a-terminal-application-crashes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You might have to wrap the program in a small bash script, but it's doable. You can redirect stderr to a file while leaving stdout to display on the screen:



#!/usr/bin/env bash

# Run my program, with stderr saved to a file
my_program 2> /tmp/stderr_output.txt

# If the program returned with anything but success, print stderr
if [ ! $! ]; then
cat /tmp/stderr_output.txt
fi


Instead of just using the cat utility, you could use your formatting utility to output the error text.






share|improve this answer



















  • 4





    $! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

    – Kusalananda
    yesterday













  • Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

    – interstar
    14 hours ago






  • 1





    @interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

    – Kusalananda
    13 hours ago











  • So basically, can't be done then?

    – interstar
    13 hours ago
















0














You might have to wrap the program in a small bash script, but it's doable. You can redirect stderr to a file while leaving stdout to display on the screen:



#!/usr/bin/env bash

# Run my program, with stderr saved to a file
my_program 2> /tmp/stderr_output.txt

# If the program returned with anything but success, print stderr
if [ ! $! ]; then
cat /tmp/stderr_output.txt
fi


Instead of just using the cat utility, you could use your formatting utility to output the error text.






share|improve this answer



















  • 4





    $! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

    – Kusalananda
    yesterday













  • Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

    – interstar
    14 hours ago






  • 1





    @interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

    – Kusalananda
    13 hours ago











  • So basically, can't be done then?

    – interstar
    13 hours ago














0












0








0







You might have to wrap the program in a small bash script, but it's doable. You can redirect stderr to a file while leaving stdout to display on the screen:



#!/usr/bin/env bash

# Run my program, with stderr saved to a file
my_program 2> /tmp/stderr_output.txt

# If the program returned with anything but success, print stderr
if [ ! $! ]; then
cat /tmp/stderr_output.txt
fi


Instead of just using the cat utility, you could use your formatting utility to output the error text.






share|improve this answer













You might have to wrap the program in a small bash script, but it's doable. You can redirect stderr to a file while leaving stdout to display on the screen:



#!/usr/bin/env bash

# Run my program, with stderr saved to a file
my_program 2> /tmp/stderr_output.txt

# If the program returned with anything but success, print stderr
if [ ! $! ]; then
cat /tmp/stderr_output.txt
fi


Instead of just using the cat utility, you could use your formatting utility to output the error text.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Jacob HumeJacob Hume

1785




1785








  • 4





    $! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

    – Kusalananda
    yesterday













  • Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

    – interstar
    14 hours ago






  • 1





    @interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

    – Kusalananda
    13 hours ago











  • So basically, can't be done then?

    – interstar
    13 hours ago














  • 4





    $! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

    – Kusalananda
    yesterday













  • Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

    – interstar
    14 hours ago






  • 1





    @interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

    – Kusalananda
    13 hours ago











  • So basically, can't be done then?

    – interstar
    13 hours ago








4




4





$! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

– Kusalananda
yesterday







$! is the PID of the most recent background task, The return status is in $?. You can't test for a non-zero integer with [ ! $? ] (this tests for an empty string, as with [ -z $? ]). It would be better to just use if ! my_program 2>file; then ...; fi.

– Kusalananda
yesterday















Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

– interstar
14 hours ago





Doesn't seem to work. If I do my_program 2> /tmp/errors.txt that still blocks my interaction on the terminal

– interstar
14 hours ago




1




1





@interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

– Kusalananda
13 hours ago





@interstar Prompts etc. (interactive dialog with the user) happens on standard error. Redirecting it to a file would put all of that into the file.

– Kusalananda
13 hours ago













So basically, can't be done then?

– interstar
13 hours ago





So basically, can't be done then?

– interstar
13 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511351%2fpipe-stderr-only-if-a-terminal-application-crashes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...