Dear fellow monks,
I'm calling a unix command from my Perl script and like to avoid any text going the STDERR or STDOUT coming from the command. So I just added a
&>/dev/null to the system string like I know it from the BASH shell prompt.
To my surprise this doesn't work, I still get the STDERR on the calling shell:
system("dd if=/dev/zero of=$SIZE bs=1M count=0 seek=$SIZEMB &>/dev/nul
+l})';
# prints to STDERR:
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.00426433 s, 2.5 GB/s
If I now change the "&>" - which affects STDOUT and STDERR - to "2>" - which only affects STDERR - it works:
system("dd if=/dev/zero of=$SIZE bs=1M count=0 seek=$SIZEMB &>/dev/nul
+l})';
# prints nothing
Why is this? It's not a problem but I like to know it anyway. The redirect is handled by the shell (==calling shell (BASH)?) not by perl, isn't it? Please enlighten me.
PS: The dd command is used to create a sparse file. Does someone know how to create sparse files with Perl without using a system command?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.