Temporarily redirecting STDOUT

F

Fil

Hi,

I'm writing some Perl (5.8.2) routines on Windows 2000. One of these
routines calls RCS functions like this:

$command = "rcs -x${rcssfx} -l $rcsname";
$rc = system($command);

I'm logging and printing my own error diagnostics, so I'm a little annoyed
that RCS prints to screen what it's doing. I'd like to redirect STDOUT
just for this command.

I understand that I can use open2 or open3 and collect separately the
STDOUT, STDERR and the return code and solve the problem. I'm really
interested here in learning to redirect STDOUT and of course recover it
afterwards. On Unix I'd redirect it to /dev/null... is there anything like
it for Perl on Windows?

Thanks in advance!

Fil
 
B

Brian McCauley

Fil said:
On Unix I'd redirect it to /dev/null... is there anything like
it for Perl on Windows?

This is a question about Windows not Perl.

IIRC the null device on Windows is called NUL:

But then again this is a Perl newsgroup not a Windows one so you shoud
not expect to find Windows expertease here.

OBperl: File::Spec->devnull :)
 
F

Fil

Hi,
This is a question about Windows not Perl.

Fair enough, but that was not my main question.
IIRC the null device on Windows is called NUL:
Thanks.

But then again this is a Perl newsgroup not a Windows one so you shoud
not expect to find Windows expertease here.

As I said, that was an aside. The post was to know how to redirect STDOUT
temporarily, then recover it.

Thanks!

Fil
 
J

Joe Smith

Fil said:
I'm really interested here in learning to redirect STDOUT and of
course recover it afterwards.

I take it that you have not attempted to use perldoc to find your answer. Try
C:\>perldoc -f open
and look at the section marked "Here is a script that saves,
redirects, and restores "STDOUT" and "STDERR" using various methods".

-Joe
 
B

Ben Morrow

Quoth Fil said:
Hi,

I'm writing some Perl (5.8.2) routines on Windows 2000. One of these
routines calls RCS functions like this:

$command = "rcs -x${rcssfx} -l $rcsname";
$rc = system($command);

I'm logging and printing my own error diagnostics, so I'm a little annoyed
that RCS prints to screen what it's doing. I'd like to redirect STDOUT
just for this command.

I understand that I can use open2 or open3 and collect separately the
STDOUT, STDERR and the return code and solve the problem. I'm really
interested here in learning to redirect STDOUT and of course recover it
afterwards. On Unix I'd redirect it to /dev/null... is there anything like
it for Perl on Windows?

cmd under Win2k has Bourne-ish redirections, so you can use

my $command = "rcs -x$rcssfx -l $rcsname > nul"; # [1]

or (for portability Win2k/Unix)

use File::Spec::Functions qw/devnull/;

my $command = "... > " . devnull;

Ben

[1] No, you really can't create a file called 'nul' under windows... (!!)
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top