portable /dev/null ?

L

Larry

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

Jürgen Exner

Larry said:
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
 
L

Larry

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.
 
A

Andreas Pürzer

Maybe you're looking for File::Spec->devnull() ?
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
 
P

Paul Lalli

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
 
S

Sisyphus

Larry said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top