[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

End-of-file character...

Sonny Chee

4/15/2007 9:42:00 PM

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-....

8 Answers

Tim Pease

4/16/2007 12:02:00 AM

0

On 4/15/07, Sonny Chee <sonny.chee@gmail.com> 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 Ziegler

4/16/2007 12:54:00 AM

0

On 4/15/07, Tim Pease <tim.pease@gmail.com> wrote:
> On 4/15/07, Sonny Chee <sonny.chee@gmail.com> 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 * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

John W Kennedy

4/16/2007 2:56:00 AM

0

Austin Ziegler wrote:
> On 4/15/07, Tim Pease <tim.pease@gmail.com> wrote:
>> On 4/15/07, Sonny Chee <sonny.chee@gmail.com> 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....

Sonny Chee

4/16/2007 2:57:00 AM

0

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-....

james.d.masters

4/16/2007 3:01:00 AM

0

On Apr 15, 2:41 pm, Sonny Chee <sonny.c...@gmail.com> 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 Chee

4/16/2007 4:05:00 AM

0

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-....

Brian Candler

4/16/2007 5:43:00 AM

0

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.

Sonny Chee

4/16/2007 6:11:00 AM

0

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-....