How can I manage to make stderr messages NOT print in the console?

Lazuli

I am currently writing a script that must, among other things, kill some processes.

I used the kill method and it works perfectly, except that, when I launch my script, some unwanted messages are print in the console saying for each of the processes that they have been "terminated".

I don't know how to get rid of these messages, so I would be grateful to anyone who can help me.

I would like these messages not to print inside the console, for they can be misleading. If I understand it correctly, those are error messages printed in the stderr stream.

Is there a way I can prevent these logs to print in the console ?

I have found on this site three issues that seem identical to mine, and proposed three differents solutions:

kill -9 $pid &> /dev/null
exec 3>&2
exec 2> /dev/null
kill $pid &> /dev/null
exec 2>&3
exec 3>&-

kill $pid

wait $pid 2>/dev/null

But sadly none of these solutions change the behavior on my script (I always have "Terminated" messages). Does anyone have any other ideas? I am relatively new to Linux and does not master the redirection of outputs yet, so maybe I am forgetting something really obvious?

A huge thanks to anybody who will try to help!

Alfe

Use a subshell to start the processes and divert the output of the subshell:

pid=$(sleep 10 >/dev/null 2>&1 & echo $!)
kill $pid

The problem is that the starting shell will monitor and notice the termination of its child and report on it.

You also can be more drastic and switch off job control (which in a script might be just what you want):

set +m
sleep 3 & pid=$!
kill $pid

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

In Chrome, how can I get the javascript console output to stdout/stderr

From Dev

How can I make subprocess get the stdout and stderr in order?

From Dev

How can I disable MongoDB log messages in console?

From Dev

Ajax with servlet - how can i manage to make doGet?

From Dev

Ajax with servlet - how can i manage to make doGet?

From Dev

How can I make attribute, which will manage an access to controller?

From Dev

How can I make git commit messages divide into multiple lines?

From Dev

How can I make cowsay to say server logging messages?

From Dev

How can I redirect the stdout and stderr of a command to both the console and a log file while outputting in real time?

From Dev

How can I capture stdout/stderr in a file but still see it in my console?

From Dev

How can i manage this request?

From Dev

How can I make a <select> in a popover display the selected option on console?

From Java

How can I pipe stderr, and not stdout?

From Dev

How can I output to STDERR with Swift?

From Dev

How can I pipe only stderr in zsh?

From Dev

How can I redirect stdout and stderr with variant?

From Dev

ionic 2: How can I get console messages from android device

From Dev

How I can log all nodejs messages showed on console to syslog in ubuntu?

From Dev

How can I make it so I can run a specific program, just by typing its name in the console?

From Dev

How can I manage my memory issue

From Dev

How can I manage overlapping DropDownBox drawers?

From Dev

How can I manage the system tray icons?

From Dev

How can I manage document sizes in Inkscape?

From Dev

How can I manage an oversensitive touchpad?

From Dev

How can I manage Visual Studio?

From Dev

How can i manage my Ble connection?

From Dev

How can I manage docker group in freeipa?

From Dev

how can I manage html tree?

From Dev

How can I make my Discord Bot delete all messages in a channel?

From Dev

How can I make my Discord Bot delete all messages in a channel?

Related Related

  1. 1

    In Chrome, how can I get the javascript console output to stdout/stderr

  2. 2

    How can I make subprocess get the stdout and stderr in order?

  3. 3

    How can I disable MongoDB log messages in console?

  4. 4

    Ajax with servlet - how can i manage to make doGet?

  5. 5

    Ajax with servlet - how can i manage to make doGet?

  6. 6

    How can I make attribute, which will manage an access to controller?

  7. 7

    How can I make git commit messages divide into multiple lines?

  8. 8

    How can I make cowsay to say server logging messages?

  9. 9

    How can I redirect the stdout and stderr of a command to both the console and a log file while outputting in real time?

  10. 10

    How can I capture stdout/stderr in a file but still see it in my console?

  11. 11

    How can i manage this request?

  12. 12

    How can I make a <select> in a popover display the selected option on console?

  13. 13

    How can I pipe stderr, and not stdout?

  14. 14

    How can I output to STDERR with Swift?

  15. 15

    How can I pipe only stderr in zsh?

  16. 16

    How can I redirect stdout and stderr with variant?

  17. 17

    ionic 2: How can I get console messages from android device

  18. 18

    How I can log all nodejs messages showed on console to syslog in ubuntu?

  19. 19

    How can I make it so I can run a specific program, just by typing its name in the console?

  20. 20

    How can I manage my memory issue

  21. 21

    How can I manage overlapping DropDownBox drawers?

  22. 22

    How can I manage the system tray icons?

  23. 23

    How can I manage document sizes in Inkscape?

  24. 24

    How can I manage an oversensitive touchpad?

  25. 25

    How can I manage Visual Studio?

  26. 26

    How can i manage my Ble connection?

  27. 27

    How can I manage docker group in freeipa?

  28. 28

    how can I manage html tree?

  29. 29

    How can I make my Discord Bot delete all messages in a channel?

  30. 30

    How can I make my Discord Bot delete all messages in a channel?

HotTag

Archive