Re: Disable output from system
by Anonymous Monk on Mar 26, 2009 at 04:42 UTC
|
|
|
V
system('tar -vxf upload.tar');
^
|
|
| [reply] [d/l] |
Re: Disable output from system
by targetsmart (Curate) on Mar 26, 2009 at 04:32 UTC
|
On unix system using bash(shell), one way of suppressing error and output
tar -vxf upload.tar 2>&1 >/dev/null
Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
| [reply] [d/l] |
|
|
tar -vxf upload.tar >/dev/null 2>&1
--
Ronald Fischer <ynnor@mm.st>
| [reply] [d/l] |
Re: Disable output from system
by rovf (Priest) on Mar 26, 2009 at 08:54 UTC
|
In addition to what already has been said, here other variations:
qx(tar ...); # Burns more CPU cycles, but who cares ;-)
use File::Spec::Functions qw(devnull);
system('tar .... >'.devnull.' 1>&2'); # works on *nix and windoze
--
Ronald Fischer <ynnor@mm.st>
| [reply] [d/l] |
|
|
Hi, Roland. You wrote:
system('tar .... >'.devnull.' 1>&2'); # works on *nix and windoze
As I can see you redirect STDOUT to devnull and then again you redirect STDOUT to STDERR... Is this correct? I think it is typo, isn't it?
| [reply] |
|
|
'....>'.devnull.' 2>&1'
and not "1>&2". I mistakingly exchanged 2 and 1. My point was that you have to redirect *first* to devnull, and *then* do the 2>&1, not the other way around.
--
Ronald Fischer <ynnor@mm.st>
| [reply] [d/l] |
|
|
Hi, Roland. You wrote: system('tar .... >'.devnull.' 1>&2'); # works on *nix and windoze As I can see you redirect STDOUT to devnull and then again you redirect STDOUT to STDERR... Is this correct? I think it is typo, isn't it ?
| [reply] |
Re: Disable output from system
by educated_foo (Vicar) on Mar 26, 2009 at 22:04 UTC
|
You can dup stdout and stderr, then close them:
sub stfu_system
{
local (*OUT, *ERR);
open OUT, ">&STDOUT";
open ERR, ">&STDERR";
close STDOUT;
close STDERR;
system @_;
open STDOUT, ">&OUT";
open STDERR, ">&ERR";
}
| [reply] [d/l] |
|
|
| [reply] |
|
|
True. For those (poorly-written) commands, s!close\s+(\w+)!open $1, '>/dev/null'!
| [reply] [d/l] |