End-of-file character...

Discussion in 'Ruby' started by Sonny Chee, Apr 15, 2007.

  1. Sonny Chee

    Sonny Chee Guest

    Hey Guys,

    Does anyone know of a cross-platform way of generating an 'end-of-file'
    character? Alternatively, does anyone know how to figure out what the
    'end-of-file' character is for a particular OS?

    Sonny.

    --
    Posted via http://www.ruby-forum.com/.
     
    Sonny Chee, Apr 15, 2007
    #1
    1. Advertising

  2. Sonny Chee

    Tim Pease Guest

    On 4/15/07, Sonny Chee <> wrote:
    > Hey Guys,
    >
    > Does anyone know of a cross-platform way of generating an 'end-of-file'
    > character? Alternatively, does anyone know how to figure out what the
    > 'end-of-file' character is for a particular OS?
    >


    I had no idea it was platform dependent. I always assumed it was ^D
    for all platforms.

    "\004" should be it.

    Blessings,
    TwP
     
    Tim Pease, Apr 16, 2007
    #2
    1. Advertising

  3. On 4/15/07, Tim Pease <> wrote:
    > On 4/15/07, Sonny Chee <> wrote:
    > > Does anyone know of a cross-platform way of generating an 'end-of-file'
    > > character? Alternatively, does anyone know how to figure out what the
    > > 'end-of-file' character is for a particular OS?

    > I had no idea it was platform dependent. I always assumed it was ^D
    > for all platforms.
    >
    > "\004" should be it.


    This is not correct. There is, in fact, no "end-of-file" character on
    Unix, and Ctrl-Z (0x26) is the end-of-file character on Windows only
    when the file is not opened in binary mode. It is conventional for a
    terminal to accept Ctrl-D (0x04) as an end of file character, but this
    is convention, not standard.

    If you want to close a file, just close it. The underlying routines
    will do the appropriate work necessary.

    -austin
    --
    Austin Ziegler * * http://www.halostatue.ca/
    * * http://www.halostatue.ca/feed/
    *
     
    Austin Ziegler, Apr 16, 2007
    #3
  4. Austin Ziegler wrote:
    > On 4/15/07, Tim Pease <> wrote:
    >> On 4/15/07, Sonny Chee <> wrote:
    >> > Does anyone know of a cross-platform way of generating an 'end-of-file'
    >> > character? Alternatively, does anyone know how to figure out what the
    >> > 'end-of-file' character is for a particular OS?

    >> I had no idea it was platform dependent. I always assumed it was ^D
    >> for all platforms.
    >>
    >> "\004" should be it.

    >
    > This is not correct. There is, in fact, no "end-of-file" character on
    > Unix, and Ctrl-Z (0x26) is the end-of-file character on Windows only
    > when the file is not opened in binary mode. It is conventional for a
    > terminal to accept Ctrl-D (0x04) as an end of file character, but this
    > is convention, not standard.


    And, except on terminals, ^Z has been obsolescent on DOS and Windows
    since DOS 1.1, twenty-five years ago.

    --
    John W. Kennedy
    "Give up vows and dogmas, and fixed things, and you may grow like That.
    ....you may come to think a blow bad, because it hurts, and not because
    it humiliates. You may come to think murder wrong, because it is
    violent, and not because it is unjust."
    -- G. K. Chesterton. "The Ball and the Cross"
    * TagZilla 0.066 * http://tagzilla.mozdev.org
     
    John W. Kennedy, Apr 16, 2007
    #4
  5. Sonny Chee

    Sonny Chee Guest

    Thanks for the clarification Austin.

    I'm actually to trying to solve the following problem. I've been
    redirecting the contents of a_file to an os_command, ie:

    os_command < a_file

    Usually a_file is very small and I have to create this file before
    invoking the os_command. Is it possible to avoid the creation of a_file
    and just pass its contents directly to os_command?

    Sonny.


    > There is, in fact, no "end-of-file" character on
    > Unix, and Ctrl-Z (0x26) is the end-of-file character on Windows only
    > when the file is not opened in binary mode. It is conventional for a
    > terminal to accept Ctrl-D (0x04) as an end of file character, but this
    > is convention, not standard.
    >
    > If you want to close a file, just close it. The underlying routines
    > will do the appropriate work necessary.
    >
    > -austin



    --
    Posted via http://www.ruby-forum.com/.
     
    Sonny Chee, Apr 16, 2007
    #5
  6. Sonny Chee

    Guest

    On Apr 15, 2:41 pm, Sonny Chee <> wrote:
    > Does anyone know of a cross-platform way of generating an 'end-of-file'
    > character? Alternatively, does anyone know how to figure out what the
    > 'end-of-file' character is for a particular OS?


    I've never heard of an end-of-file character. EOF happens when a file
    handle reaches the end of a file - not when it hits a specific
    character. Many binary file types use null padding at the end
    (character \0) although this is not an EOF character per se. To
    generate a null character, you could do this "\0".
     
    , Apr 16, 2007
    #6
  7. Sonny Chee

    Sonny Chee Guest

    Hey Guys,

    Thanks for all the answers. I just found the answer with a little
    googling. It looks like I want to use the pipe operator... as in:

    echo a_file_contents | os_command

    Thanks, again.

    Sonny.

    > I'm actually to trying to solve the following problem. I've been
    > redirecting the contents of a_file to an os_command, ie:
    >
    > os_command < a_file
    >
    > Usually a_file is very small and I have to create this file before
    > invoking the os_command. Is it possible to avoid the creation of a_file
    > and just pass its contents directly to os_command?
    >
    > Sonny.


    --
    Posted via http://www.ruby-forum.com/.
     
    Sonny Chee, Apr 16, 2007
    #7
  8. On Mon, Apr 16, 2007 at 11:56:48AM +0900, Sonny Chee wrote:
    > I'm actually to trying to solve the following problem. I've been
    > redirecting the contents of a_file to an os_command, ie:
    >
    > os_command < a_file
    >
    > Usually a_file is very small and I have to create this file before
    > invoking the os_command. Is it possible to avoid the creation of a_file
    > and just pass its contents directly to os_command?


    If you are running os_command from Ruby, use IO.popen to run it. You then
    get an IO object for a pipe to squirt data at it.
     
    Brian Candler, Apr 16, 2007
    #8
  9. Sonny Chee

    Sonny Chee Guest

    Awesome, thanks Brian. Great idea!

    Sonny.


    Brian Candler wrote:
    > On Mon, Apr 16, 2007 at 11:56:48AM +0900, Sonny Chee wrote:
    >> I'm actually to trying to solve the following problem. I've been
    >> redirecting the contents of a_file to an os_command, ie:
    >>
    >> os_command < a_file
    >>
    >> Usually a_file is very small and I have to create this file before
    >> invoking the os_command. Is it possible to avoid the creation of a_file
    >> and just pass its contents directly to os_command?

    >
    > If you are running os_command from Ruby, use IO.popen to run it. You
    > then
    > get an IO object for a pipe to squirt data at it.



    --
    Posted via http://www.ruby-forum.com/.
     
    Sonny Chee, Apr 16, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Aguilar
    Replies:
    4
    Views:
    3,680
    Lionel B
    May 9, 2005
  2. simon.alexandre
    Replies:
    3
    Views:
    695
    simon.alexandre
    Jan 11, 2005
  3. Spacebar265

    Scanning a file character by character

    Spacebar265, Feb 5, 2009, in forum: Python
    Replies:
    18
    Views:
    495
  4. Jimmy
    Replies:
    3
    Views:
    358
    J. J. Farrell
    Sep 9, 2011
  5. Jimmy
    Replies:
    13
    Views:
    674
    Peter Nilsson
    Sep 21, 2011
Loading...

Share This Page