Solved

STDIN STDOUT?

Posted on 2000-02-17
2
1,057 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl 101 11 76
Port 80 requests 16 95
Awk Question 2 127
How to prepend a string to a matched string using regex and substitution in Perl 5 74
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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