EOF in Java

Programming, for all ages and all languages.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

EOF in Java

Post 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?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:EOF in Java

Post 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?
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:EOF in Java

Post by Neo »

Then what is '^D'? is it just a way of telling the stdin that input has stopped?
Only Human
neo(out)

Re:EOF in Java

Post by neo(out) »

Is there any way I could send the CTRL+D marker to the file that I have created?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:EOF in Java

Post 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?
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:EOF in Java

Post 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?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:EOF in Java

Post 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?)
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:EOF in Java

Post 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?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:EOF in Java

Post 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.
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:EOF in Java

Post by Neo »

What does EOF really translate to? Will it be understood by the Terminal?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:EOF in Java

Post 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.
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:EOF in Java

Post by Neo »

Nope that doesn't work I just get a blank file with that. I am doing the logout-login thing for now.
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:EOF in Java

Post 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.
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:EOF in Java

Post 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.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:EOF in Java

Post 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.
Only Human
Post Reply