EOF in Java
EOF in Java
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
Re:EOF in Java
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?
Or, to phrase it differently: How would you send EOF in C?
Every good solution is obvious once you've found it.
Re:EOF in Java
Then what is '^D'? is it just a way of telling the stdin that input has stopped?
Only Human
Re:EOF in Java
Is there any way I could send the CTRL+D marker to the file that I have created?
Re:EOF in Java
Exactly.Neo wrote: Then what is '^D'? is it just a way of telling the stdin that input has stopped?
Closing it?Is there any way I could send the CTRL+D marker to the file that I have created?
Every good solution is obvious once you've found it.
Re:EOF in Java
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?
Any idea how I can?
Only Human
Re:EOF in Java
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?)
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.
Re:EOF in Java
It's not my code so cannot post it. It does something like this.
Now how do i send a CTRL+D to this?
Code: Select all
objectname.login("client ip");
objectname.typestring("cat>file1");
objectname.typestring("lots of garbage");
Only Human
Re:EOF in Java
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.
...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.
Re:EOF in Java
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.
Re:EOF in Java
Nope that doesn't work I just get a blank file with that. I am doing the logout-login thing for now.
Only Human
Re:EOF in Java
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.
Re:EOF in Java
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
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