Page 1 of 2
EOF in Java
Posted: Mon Mar 07, 2005 5:52 am
by Neo
How do you send the EOF char to a file that I've opened in Java. Actually I created the file using the 'cat' command that was called from within the Java code. I am able to create a file but not able to end it with the EOF char. How can i send this too?
Re:EOF in Java
Posted: Mon Mar 07, 2005 6:35 am
by Solar
There is no "EOF character". EOF is a flag outside of the character set, a value that does not exist in any character. It is never sent, it is received when you try to read past the end of a file.
Or, to phrase it differently: How would you send EOF in C?
Re:EOF in Java
Posted: Mon Mar 07, 2005 7:23 am
by Neo
Then what is '^D'? is it just a way of telling the stdin that input has stopped?
Re:EOF in Java
Posted: Mon Mar 07, 2005 7:46 am
by neo(out)
Is there any way I could send the CTRL+D marker to the file that I have created?
Re:EOF in Java
Posted: Mon Mar 07, 2005 8:11 am
by Solar
Neo wrote:
Then what is '^D'? is it just a way of telling the stdin that input has stopped?
Exactly.
Is there any way I could send the CTRL+D marker to the file that I have created?
Closing it?
Re:EOF in Java
Posted: Tue Mar 08, 2005 6:23 am
by Neo
How do I close it. I am using the 'cat' command to create the files.I have a progarm that telnets to a remote machine and can issue commands on the remote terminal. So I use the 'cat' command to create a file there, but have no way of closing it i.e. sending the CTRL+D char.
Any idea how I can?
Re:EOF in Java
Posted: Tue Mar 08, 2005 6:58 am
by Solar
Now you got me confused.
How did you "call cat"? What is your handle on the file that you cannot close it? (Perhaps posting the piece of code might help?)
Re:EOF in Java
Posted: Tue Mar 08, 2005 7:18 am
by Neo
It's not my code so cannot post it.
It does something like this.
Code: Select all
objectname.login("client ip");
objectname.typestring("cat>file1");
objectname.typestring("lots of garbage");
Now how do i send a CTRL+D to this?
Re:EOF in Java
Posted: Tue Mar 08, 2005 8:12 am
by Solar
objectname.logout()
...or...
objectname.login("client ip");
objectname.typestring("cat > file1 << EOF");
objectname.typestring("lots of garbage");
objectname.typestring("EOF");
...if you want to keep the connection. Note that "EOF" could be any other string in this case.
Re:EOF in Java
Posted: Tue Mar 08, 2005 9:20 pm
by Neo
What does EOF really translate to? Will it be understood by the Terminal?
Re:EOF in Java
Posted: Wed Mar 09, 2005 1:57 am
by Solar
It's a shell function. Read input until a certain character sequence is encountered. As I said, you could just as well use "END" instead of "EOF" in my example. No terminal magic involved.
Re:EOF in Java
Posted: Wed Mar 09, 2005 5:53 am
by Neo
Nope that doesn't work I just get a blank file with that. I am doing the logout-login thing for now.
Re:EOF in Java
Posted: Wed Mar 09, 2005 6:04 am
by Solar
Hard to say what's going wrong without seeing the real code, as I've still no idea how the connection is actually made and how 'cat' is, exactly, invoked.
Re:EOF in Java
Posted: Wed Mar 09, 2005 6:53 am
by Candy
If you really have an emulated environment equivalent to the normal one, try to send a (char)4. ctrl-D should send that too, might just work.
Re:EOF in Java
Posted: Wed Mar 09, 2005 6:56 am
by Neo
I am only able to send strings to the terminal. I think that is the problem, if there was any way of send the CTRL+D as a string (is this even possible?) then maybe this will work.