Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Null device

0 views
Skip to first unread message

Narasimha Rao, Mothukuri

unread,
Jun 16, 1999, 3:00:00 AM6/16/99
to

I want to redirect my ouput to a null stream. Is there any way to do? My
code looks as follows:

(condition)?(mystream):cnull;
condition - condition which iam checking,
mystream- a stream.
cnull - iam considering a null stream, if i direct any output to that
stream it should do nothing.

Is there any stream like cnull, can i open /dev/null and direct the
output to that?

thanks in advance
M.N.Rao


Paul Lutus

unread,
Jun 16, 1999, 3:00:00 AM6/16/99
to
Null streams are platform-dependent. Ask in a platform-specific newsgroup.

--

Paul Lutus
www.arachnoid.com

Narasimha Rao, Mothukuri wrote in message
<3767B60B...@sesd.cig.mot.com>...

Steve Horne

unread,
Jun 16, 1999, 3:00:00 AM6/16/99
to
"Narasimha Rao, Mothukuri" wrote:
>
> I want to redirect my ouput to a null stream. Is there any way to do? My
> code looks as follows:
>
[ non-code gibberish deleted ]

>
> Is there any stream like cnull, can i open /dev/null and direct the
> output to that?

Sure, you can open /dev/null if your platform has such a file or
device. It is a non-portable solution that won't work on non-Unix like
systems, though. Also, realize that all the normal file
buffering/writing will take place, so you will have some overhead there,
it's just that the OS will throw away everything after you have written
it.

Hope this helps,
-Steve

Paul Lutus

unread,
Jun 16, 1999, 3:00:00 AM6/16/99
to
Null streams are platform-dependent. Ask in a platform-specific newsgroup.

--

Paul Lutus
www.arachnoid.com

Narasimha Rao, Mothukuri wrote in message
<3767B60B...@sesd.cig.mot.com>...
>

>I want to redirect my ouput to a null stream. Is there any way to do? My
>code looks as follows:
>

>(condition)?(mystream):cnull;
>condition - condition which iam checking,
>mystream- a stream.
>cnull - iam considering a null stream, if i direct any output to that
>stream it should do nothing.
>

>Is there any stream like cnull, can i open /dev/null and direct the
>output to that?
>

>thanks in advance
>M.N.Rao
>

Flavius Sabinus

unread,
Jun 16, 1999, 3:00:00 AM6/16/99
to
In article <3767DCF9...@bridge.bst.bls.com>, Steve Horne <steve....@bridge.bst.bls.com> wrote:

>"Narasimha Rao, Mothukuri" wrote:
>>
>> I want to redirect my ouput to a null stream. Is there any way to do? My
>> code looks as follows:
>>
>[ non-code gibberish deleted ]

>>
>> Is there any stream like cnull, can i open /dev/null and direct the
>> output to that?
>
>Sure, you can open /dev/null if your platform has such a file or
>device. It is a non-portable solution that won't work on non-Unix like
>systems, though. Also, realize that all the normal file
>buffering/writing will take place, so you will have some overhead there,
>it's just that the OS will throw away everything after you have written
>it.

Most systems have a /dev/null equivalent. NULL: works on VMS and Windoze.

Creating a system-independent NULL would be an easy task. Just create a stream
but that never writes anything.

John - N8086N
Big brother is watching. Disable cookies in your web browser.
-------------------------------------------
Wise man says "Never use a bank with the initials F. U."
-------------------------------------------
Are you interested in a professional society or
guild for programmers? Want to fight section 1706?


See www.programmersguild.org
Newsgroup: us.issues.occupations.computer-programmers


EMail Address:
_m-i-a-n-o_@_c_o_l_o_s_s_e_u_m_b_u_i_l_d_e_r_s._c_o_m_


George

unread,
Jun 18, 1999, 3:00:00 AM6/18/99
to
"Narasimha Rao, Mothukuri" <moth...@sesd.cig.mot.com> wrote:

>
> I want to redirect my ouput to a null stream. Is there any way to do? My
> code looks as follows:
>

> (condition)?(mystream):cnull;
> condition - condition which iam checking,
> mystream- a stream.
> cnull - iam considering a null stream, if i direct any output to that
> stream it should do nothing.
>

Which language is this?

> Is there any stream like cnull, can i open /dev/null and direct the
> output to that?
>

> thanks in advance
> M.N.Rao

....message ends.....

Dietmar Kuehl

unread,
Jun 18, 1999, 3:00:00 AM6/18/99
to
Hi,
Paul Lutus (nos...@nosite.com) wrote:
: Null streams are platform-dependent. Ask in a platform-specific newsgroup.

Sorry, but I disagree. Although /dev/null is indeed platform specific,
it is easy, not to say trivial, to create a null device in C++. Here is
one for starters:

#include <streambuf>
#include <ostream>

template <class cT, class traits = std::char_traits<cT> >
class basic_nullbuf: public std::basic_streambuf<cT, traits>
{
typename traits::int_type overflow(typename traits::int_type c)
{
return traits::not_eof(c); // indicate success
}
};

template <class cT, class traits = std::char_traits<cT> >
class basic_onullstream: public std::basic_ostream<cT, traits>
{
public:
basic_onullstream():
std::basic_ios<cT, traits>(&m_sbuf),
std::basic_ostream<cT, traits>(&m_sbuf)
{
init(&m_sbuf);
}

private:
basic_nullbuf<cT, traits> m_sbuf;
};

typedef basic_onullstream<char> onullstream;
typedef basic_onullstream<wchar_t> wonullstream;

This code is (except for potential typos, I just typed the code and
haven't tested it) only using features of the C++ standard. Thus, your
redirection is [again (I have noted that on several other articles,
too)] invalid. Please make sure that you only direct stuff which is
really platform specific to other newsgroup!
--
<mailto:dietma...@claas-solutions.de>
<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic

0 new messages