Forum: Ruby End-of-file character...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sonny C. (Guest)
on 2007-04-16 01:41
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.
Tim P. (Guest)
on 2007-04-16 04:02
(Received via mailing list)
On 4/15/07, Sonny C. <removed_email_address@domain.invalid> 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
Austin Z. (Guest)
on 2007-04-16 04:54
(Received via mailing list)
On 4/15/07, Tim P. <removed_email_address@domain.invalid> wrote:
> On 4/15/07, Sonny C. <removed_email_address@domain.invalid> 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
Sonny C. (Guest)
on 2007-04-16 06:56
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
John W. Kennedy (Guest)
on 2007-04-16 07:01
(Received via mailing list)
Austin Z. wrote:
> 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
unknown (Guest)
on 2007-04-16 07:05
(Received via mailing list)
On Apr 15, 2:41 pm, Sonny C. <removed_email_address@domain.invalid> 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".
Sonny C. (Guest)
on 2007-04-16 08:04
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.
Brian C. (Guest)
on 2007-04-16 09:44
(Received via mailing list)
On Mon, Apr 16, 2007 at 11:56:48AM +0900, Sonny C. 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.
Sonny C. (Guest)
on 2007-04-16 10:11
Awesome, thanks Brian.  Great idea!

Sonny.


Brian C. wrote:
> On Mon, Apr 16, 2007 at 11:56:48AM +0900, Sonny C. 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.
This topic is locked and can not be replied to.