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.
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.
On 4/15/07, Sonny C. [email protected] 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
On 4/15/07, Tim P. [email protected] wrote:
On 4/15/07, Sonny C. [email protected] 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
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
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”
On Apr 15, 2:41 pm, Sonny C. [email protected] 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”.
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.
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.
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs