Stream names

This is a discussion on Stream names within the C++ Programming forums, part of the General Programming Boards category; Alright, can someone finish this list? All OS(defined by implementation): stdin stdout stderr Windows / Dos Console = CON Printer ...

  1. #1
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540

    Stream names

    Alright, can someone finish this list?

    All OS(defined by implementation):

    stdin
    stdout
    stderr

    Windows / Dos

    Console = CON
    Printer = PRN

    UNIX

    Console:
    Printer:

    Apple:

    Console:
    Printer:

    Lynix:

    Console:
    Printer:
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Consoles in Unix, uh oh...
    My Linux machine has about 330 tty?? entries in the /dev/ directory, all of these are, in theory, consoles. In addition, it has the stdin, stdout and stderr devices, which address the current console. Then there's about 250 pseudo-terminals. And I believe the entries in the vc/ directory are some terminal-like things too.

    The only printer connected is referred to alternatively as /dev/lp0 or as /dev/printers/0.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    /dev/lp0 or as /dev/printers/0.
    So these would be the stream names? Maybe I am not being clear, or most likely I'm stupid , lets say I wanted to open a stream, I would do it like:
    Code:
        fstream myStream;
        myStream.open(streamName, ios_base::open_mode Mode);
    Now in windows/DOS if I wanted to open the printer stream, I could use "PRN" for stream name, conversly if I wanted another stream to the monitor I could use "CON" for the streamName.
    Last edited by andyhunter; 02-11-2005 at 07:26 AM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Yes, but Unix doesn't have these special built-in names. Unix instead uses special file-like things, the device nodes. These are far more flexible - but as a consequence they're also less predictable.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Ok, so can these device nodes be treated as streams? Or better question how can you print? Or do you have to rely heavily on the OS?
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    They can be treated like files. And yes, you can print by opening lp0. However, remember that the printer needs a "\r\n" pair to properly start a new line, and Unix iostreams won't do the conversion from the in-program "\n" for you.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Thankyou. So the current list is:

    All OS
    stdin
    stdout
    stderr
    Code:
               Windows/Dos Unix / Lynix Mac
    Printer    PRN              lp0             ?
    Console    CON               ?             ?
    Evidently there are too many console types in Unix to list? However stdout will give you the console.

    *edit*
    In case I am not being clear I am hoping for someone to help fill in the question marks.
    Last edited by andyhunter; 02-11-2005 at 02:51 PM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Unless it's been redirected
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    yes, and that is why I am looking for the device node. How would you set stdout back in unix after you redirect it with freopen?
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Good question. When you're in an SSH session, you can find out the pseudo-terminal with the SSH_TTY environment variable. But I'm not aware of any other way to find out your current terminal. Yet there must be, because ps displays the information. There's also the tty program, which displays the tty your stdin is linked to. Or "not a tty" if it's redirected.

    You might want to look at the source of this little app.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    .
    Join Date
    Nov 2003
    Posts
    307
    I'm not good in C++ anymore, but unix has standard system calls to identify terminals.

    To start with SUS2 compliance dictates that "/dev/tty" can be used to open or reference the controlling terminal without knowing the "real" name.

    stdio.h --
    ctermid() - pathname of controlling terminal usually returns /dev/tty which is not useful.

    unistd.h --
    ttyname() - terminal name ie., pts/13 or whatever.
    ttyname_r() the atomic version of ttyname
    isatty() will tell you if the fd of the stream is attached to a terminal.

    code fragment
    Code:
    #include <unistd.h>
    #include <stdio.h>
    
    char *mytty;
    if((mytty=ttyname(STDIN_FILENO))==NULL)
    {
         printf("Not a tty\n");
         
    }
    else
    {
        printf("%s\n", mytty);
    }
    Last edited by jim mcnamara; 02-11-2005 at 03:27 PM.

  12. #12
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    To start with SUS2 compliance dictates that "/dev/tty" can be used to open or reference the controlling terminal without knowing the "real" name.
    Great information!!!. Exactly what I was looking for. Now the list is:
    Code:
     Windows/Dos Unix / Lynix Mac
    Printer    PRN             /dev/lp0         ?
    Console    CON             /dev/tty         ?
    Any mac programmers out there?
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Discard wrong data from stream
    By mesmer in forum C Programming
    Replies: 7
    Last Post: 11-16-2008, 01:30 AM
  2. Closing a stream
    By cunnus88 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2008, 04:15 PM
  3. reading folder names..how is it done ?
    By roalme00 in forum C++ Programming
    Replies: 8
    Last Post: 01-11-2008, 09:34 AM
  4. Help! About text stream and binary stream
    By Antigloss in forum C Programming
    Replies: 1
    Last Post: 09-01-2005, 08:40 AM
  5. Replies: 9
    Last Post: 07-01-2002, 07:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21