| Author |
portable /dev/null ?
|
|
|
| I want to run an external command using "system" but discard its
standard output. I know under *nix I could do:
system 'myCmd > /dev/null';
and Windows:
system 'myCmd > nul';
but is there a more portable way to do that?
| |
| Jürgen Exner 2007-06-29, 7:03 pm |
| Larry wrote:
> I want to run an external command using "system" but discard its
> standard output. I know under *nix I could do:
>
> system 'myCmd > /dev/null';
>
> and Windows:
>
> system 'myCmd > nul';
>
> but is there a more portable way to do that?
If you would drop your requirement of using system(), then you could use
backticks and capture (and then discard) the output in your Perl program.
jue
| |
|
| On Jun 29, 11:03 am, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> Larry wrote:
>
>
>
>
>
> If you would drop your requirement of using system(), then you could use
> backticks and capture (and then discard) the output in your Perl program.
>
> jue
I thought of the backticks method, but I remember that being a problem
in Windows the last time i tried it. Also, even if backticks works, I
would prefer an option that discarded the output immediately, so that
memory is not wasted if the output is large.
| |
| Andreas Pürzer 2007-06-29, 7:03 pm |
| Larry schrieb:
> On Jun 29, 11:03 am, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>
Maybe you're looking for File::Spec->devnull() ?
[color=darkred]
>
>
> I thought of the backticks method, but I remember that being a problem
> in Windows the last time i tried it.
perl -e "print `echo foo > nul`"
works fine here.
HTH,
Andreas Pürzer
--
Have Fun,
and if you can't have fun,
have someone else's fun.
The Beautiful South
| |
| Paul Lalli 2007-06-29, 7:03 pm |
| On Jun 29, 10:57 am, Larry <larry.grant...@gmail.com> wrote:
> I want to run an external command using "system" but discard its
> standard output. I know under *nix I could do:
>
> system 'myCmd > /dev/null';
>
> and Windows:
>
> system 'myCmd > nul';
>
> but is there a more portable way to do that?
IIRC, the IO::All module has a devnull() method. You might want to
look into it. The module is available on the CPAN.
Paul Lalli
| |
|
|
| Sisyphus 2007-06-30, 8:02 am |
|
"Larry" <larry.grant.dc@gmail.com> wrote in message
news:1183129074.575021.46410@w5g2000hsg.googlegroups.com...
>I want to run an external command using "system" but discard its
> standard output. I know under *nix I could do:
>
> system 'myCmd > /dev/null';
>
> and Windows:
>
> system 'myCmd > nul';
>
> but is there a more portable way to do that?
>
You could use File::Spec. Then the code becomes (untested):
my $devnull = File::Spec->devnull();
system("myCmd > $devnull"); # should be portable
Cheers,
Rob
|
|
|
|