Solved

STDIN STDOUT?

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now