Solved

STDIN STDOUT?

Posted on 2000-02-17
2
1,059 Views
Last Modified: 2008-02-26
According to a "teach yourself Perl" book I've got here, I can reset STDOUT to the default (ie. normal STDOUT) by doing this :

open(STDOUT,">-");

However, if I do this :

print "Hello1\n";
open(STDOUT,">/dev/null");
print "Hello2\n";
open(STDOUT,">-");
print "Hello3\n";

I'd expect to see :
Hello1
Hello3

however all I see is :
Hello1

I need to system() a process which refuses to run quietly (even with direction to /dev/null) so I want Perl to turn off stdout temporarily, but then I need it back....hayelp!
0
Comment
Question by:ptruman
2 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2531860
try this. it works


#!/usr/local/bin/perl

open(STDOUT,">-");
print "Hello1\n";
close(STDOUT);
open(STDOUT,">/dev/null");
print "Hello2\n";
close(STDOUT);
open(STDOUT,">-");
print "Hello3\n";
close(STDOUT);
0
 
LVL 84

Expert Comment

by:ozo
ID: 2531881
print "Hello1\n";
open(OLDOUT, ">&STDOUT");
open(STDOUT,">/dev/null");
print "Hello2\n";
open(STDOUT, ">&OLDOUT");
print "Hello3\n";
#see `perldoc -f open` and `perldoc -q STDERR`
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTTP Error 502.2 - Bad Gateway 3 222
Perl - Mawk 2 101
How to strip .csv from file name 9 83
Perl tar error 8 67
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question