For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2007 > portable /dev/null ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author portable /dev/null ?
Larry

2007-06-29, 7:03 pm

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


Larry

2007-06-29, 7:03 pm

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

Kunzdakente

2007-06-30, 2:47 am

Hilary Swank and Halle Berry Licking Pussy!
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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com