www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Creating stream from stdout

reply Mandeep <mandeep brars.co.in> writes:
I have created a stream from stdout by using the following method.

new CFile(stdout.getFP(), FileMode.Out)

It works but is this the correct way or is there a better way to achieve 
this without FP.

Thanks & Regards
Mandeep
Apr 23 2011
next sibling parent reply =?ISO-8859-1?Q?Ali_=C7ehreli?= <acehreli yahoo.com> writes:
On 04/23/2011 04:23 AM, Mandeep wrote:
 I have created a stream from stdout by using the following method.

 new CFile(stdout.getFP(), FileMode.Out)

 It works but is this the correct way or is there a better way to achieve
 this without FP.

 Thanks & Regards
 Mandeep

Consider streams gone from D. They are deprecated in favor of a "range" interface. std.range and std.algorithm have examples of ranges that are first introduced in this article (with different names in Phobos): http://www.informit.com/articles/printerfriendly.aspx?p=1407357 Ali
Apr 23 2011
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
 On 04/23/2011 04:23 AM, Mandeep wrote:
 I have created a stream from stdout by using the following method.
 
 new CFile(stdout.getFP(), FileMode.Out)
 
 It works but is this the correct way or is there a better way to achieve
 this without FP.
 
 Thanks & Regards
 Mandeep

Consider streams gone from D. They are deprecated in favor of a "range" interface. std.range and std.algorithm have examples of ranges that are first introduced in this article (with different names in Phobos): http://www.informit.com/articles/printerfriendly.aspx?p=1407357

That's not quite true. You've misunderstood. Ranges are heavily used in Phobos, and most modules use them and are going to use them. std.stream is the current module for streaming I/O in Phobos. However, it is old and does _not_ use them. It probably has other issues with it that make it so that it's considered deficient anyway, but I haven't really used it much, so I'm not all that familiar with it. Regardless, because std.stream is old and does not use streams, it's going to be replaced with a new module (possibly called std.stream) which _does_ use ranges. However, that new module has not been completed or even completely designed as far as its basic API goes. So, std.stream as it stands is going away. None of the current I/O streaming in Phobos will be sticking around in the long run. However, it will be replaced with new I/O streaming functionality which is range-based at some point in the future. As the new stuff is nowhere near complete, the old stuff is still there, but eventually it won't be. - Jonathan M Davis
Apr 23 2011
parent reply =?ISO-8859-1?Q?Ali_=C7ehreli?= <acehreli yahoo.com> writes:
On 04/23/2011 04:32 PM, Jonathan M Davis wrote:
 On 04/23/2011 04:23 AM, Mandeep wrote:
 I have created a stream from stdout by using the following method.

 new CFile(stdout.getFP(), FileMode.Out)

 It works but is this the correct way or is there a better way to 



 this without FP.

 Thanks&  Regards
 Mandeep

Consider streams gone from D. They are deprecated in favor of a "range" interface. std.range and std.algorithm have examples of ranges that are first introduced in this article (with different names in Phobos): http://www.informit.com/articles/printerfriendly.aspx?p=1407357

That's not quite true. You've misunderstood.

Which of my three statements are you referring to? Your use of vague words like "that" doesn't help.
 Ranges are heavily used in Phobos, and most modules use them and are 

 use them. std.stream is the current module for streaming I/O in Phobos.

What is "streaming I/O"? stdin and stdout are streaming I/O too. Do you consider them non-Phobos?
 However, it is old and does _not_ use them. It probably has other 

 it that make it so that it's considered deficient anyway, but I 

 used it much, so I'm not all that familiar with it. Regardless, because
 std.stream is old and does not use streams, it's going to be replaced 

 new module (possibly called std.stream) which _does_ use ranges. 

 new module has not been completed or even completely designed as far 

 basic API goes.

 So, std.stream as it stands is going away. None of the current I/O 

 in Phobos will be sticking around in the long run. However, it will be
 replaced with new I/O streaming functionality which is range-based at 

 point in the future. As the new stuff is nowhere near complete, the 

 is still there, but eventually it won't be.

I read the above multiple times. Unfortunately I can't understand more than what I already knew. Let me get back to my three statements: 1) Streams are gone from D. Since with "streams", I can only possibly mean what is already in D, I mean those streams are gone from D. I shouldn't need to disclaim that some module in the future may be related to streams. 2) Streams that are currently present in D are deprecated in favor of a new interface that will use ranges, or be ranges. 3) The seminal paper that I linked above is it. Ali
Apr 23 2011
parent =?ISO-8859-1?Q?Ali_=C7ehreli?= <acehreli yahoo.com> writes:
On 04/23/2011 10:37 PM, Jonathan M Davis wrote:

 stdin and stdio are _not_ streams.

How do you define "stream"? stdin and stdout are streams.
 They're instances of std.stdio, and they
 are _not_ going away. As far as I know, nothing in std.stdio is going 

That's correct. I've been inconsistent: When I said that D's streams were going away, I meant std.stream and std.cstream. Regardless, nothing can change the fact that just like C's stdin and stdout, D's stdin and stdout are streams. $ man stdin | head STDIN(3) Linux Programmer's Manual STDIN(3) NAME stdin, stdout, stderr - standard I/O streams SYNOPSIS #include <stdio.h> Ali
Apr 24 2011
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
 On 04/23/2011 04:32 PM, Jonathan M Davis wrote:
  >> On 04/23/2011 04:23 AM, Mandeep wrote:
  >>> I have created a stream from stdout by using the following method.
  >>> 
  >>> new CFile(stdout.getFP(), FileMode.Out)
  >>> 
  >>> It works but is this the correct way or is there a better way to
 
 achieve
 
  >>> this without FP.
  >>> 
  >>> Thanks&  Regards
  >>> Mandeep
  >> 
  >> Consider streams gone from D. They are deprecated in favor of a "range"
  >> interface. std.range and std.algorithm have examples of ranges that are
  >> 
  >> first introduced in this article (with different names in Phobos):
  >>     http://www.informit.com/articles/printerfriendly.aspx?p=1407357
  > 
  > That's not quite true. You've misunderstood.
 
 Which of my three statements are you referring to? Your use of vague
 words like "that" doesn't help.
 
  > Ranges are heavily used in Phobos, and most modules use them and are
 
 going to
 
  > use them. std.stream is the current module for streaming I/O in Phobos.
 
 What is "streaming I/O"? stdin and stdout are streaming I/O too. Do you
 consider them non-Phobos?
 
  > However, it is old and does _not_ use them. It probably has other
 
 issues with
 
  > it that make it so that it's considered deficient anyway, but I
 
 haven't really
 
  > used it much, so I'm not all that familiar with it. Regardless, because
  > std.stream is old and does not use streams, it's going to be replaced
 
 with a
 
  > new module (possibly called std.stream) which _does_ use ranges.
 
 However, that
 
  > new module has not been completed or even completely designed as far
 
 as its
 
  > basic API goes.
  > 
  > So, std.stream as it stands is going away. None of the current I/O
 
 streaming
 
  > in Phobos will be sticking around in the long run. However, it will be
  > replaced with new I/O streaming functionality which is range-based at
 
 some
 
  > point in the future. As the new stuff is nowhere near complete, the
 
 old stuff
 
  > is still there, but eventually it won't be.
 
 I read the above multiple times. Unfortunately I can't understand more
 than what I already knew.
 
 Let me get back to my three statements:
 
 1) Streams are gone from D. Since with "streams", I can only possibly
 mean what is already in D, I mean those streams are gone from D. I
 shouldn't need to disclaim that some module in the future may be related
 to streams.
 
 2) Streams that are currently present in D are deprecated in favor of a
 new interface that will use ranges, or be ranges.
 
 3) The seminal paper that I linked above is it.

stdin and stdio are _not_ streams. They're instances of std.stdio, and they are _not_ going away. As far as I know, nothing in std.stdio is going away. std.stream as it stands (which _does_ using streaming I/O) _is_ going away. It will be replaced by another module which uses range-based streaming I/O. You were saying that streams will be going away in favor of ranges, which is not true. While it makes a lot of sense to treat streams as ranges, they are definitely different concepts, and neither will be replacing the other. The current stream API in std.stream will be going away in favor of a new, range- based stream API. But streams themselves as a concept will not be going away. - Jonathan M Davis
Apr 23 2011