1

I'm in the process of creating some bash script, and I would need to silence the parted command in some use cases. The answers of this question doesn't help.

Here's the piece of code I'm using:

parted -s $1 mklabel gpt &> /dev/null

And here's the output, no matter the output redirection:

[root@localhost tmp]# parted -s /dev/sda mklabel gpt &> /dev/null
 sda:
[root@localhost tmp]#

Is there's any way, even a tricky one, to silence this command?

Community
  • 1
  • 1
Pierre
  • 6,084
  • 5
  • 32
  • 52
  • The link behind "this question" doesn't work – Aaron Digulla Jun 24 '14 at 08:37
  • Corrected. Just a link to the "duplicate" question :) – Pierre Jun 24 '14 at 08:39
  • @Pierre I don't know how `parted` works. Since you already redirect stdout and stderr, the only way I can think this can happen is when the output(or error) comes from the shell that's not part of the `parted` itself. You can try: `{ parted -s $1 mklabel gpt &> /dev/null ; } &>/dev/null` if that's the case. – P.P Jun 24 '14 at 08:40
  • @BlueMoon thanks for your suggestion. Unfortunately, the result is the same. – Pierre Jun 24 '14 at 08:44
  • @Pierre Other reason may be that your shell doesn't support `&>`. So you explicitly redirect them: `parted -s $1 mklabel gpt 2>&1 > /dev/null` or `{ parted -s $1 mklabel gpt 2>&1 > /dev/null ; } 2>&1 >/dev/null` – P.P Jun 24 '14 at 08:48
  • @BlueMoon Must be the parted command itself, I guess. The shell supports `&>`, and your idea doesn't work either. – Pierre Jun 24 '14 at 08:52
  • You can't be doing what you think you are. If it appears on the terminal, then it seems to me it must be going to stdout or stderr. So the redirection of those isn't working. Can you check with a command other than parted that you are successfully redirecting stdout/stderr? – The Archetypal Paul Jun 24 '14 at 09:08
  • @Paul I just tested. `ls . &> /dev/null` returns nothing, so does `ls nonexistent &> /dev/null`. The redirection seems to work. – Pierre Jun 24 '14 at 09:15
  • Then I'm out of ideas. Unless parted is writing directly to the terminal, I can't see how the output is getting there... – The Archetypal Paul Jun 24 '14 at 09:31
  • This question hints that parted does require an actual terminal: http://stackoverflow.com/questions/14770738/parted-mklabel-raises-an-error-through-python-subprocess – The Archetypal Paul Jun 24 '14 at 09:33
  • Try it this way `> /dev/null 2>&1` –  Jun 24 '14 at 10:20
  • Use strace to invoke your command and examine the system calls where the offending output occurs. It may be that you're running from the console and parted writes directly to the console device. – Austin Phillips Jun 24 '14 at 11:49

2 Answers2

0

Explicitly redirect stdout and stderr to /dev/null.

parted -s $1 mklabel gpt 1>>/dev/null 2>>/dev/null

0

Dude, the output "sda:" is not from parted, it's a kernel's print.

Pyih
  • 91
  • 2
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 31 '23 at 16:38