eof

How to run bash command during redirect << EOF

我的未来我决定 提交于 2019-12-10 20:38:08
问题 I know there's some way to run bash command during redirect, but I don't know how exactly it is done. I want to do something like this: #!/bin/bash mysql -uUser -pPasswd << EOF echo 'I wanna echo something by using echo which is run by bash' use Mydb some sql commands here commit; EOF I had ever done that by mistake by using " in the "<< EOF" , but failed to make it now. 回答1: You can use system command from within the mysql command line client: #!/bin/bash mysql -uUser -pPasswd << EOF system

How do we terminate this C code?

无人久伴 提交于 2019-12-10 19:35:32
问题 This c code is from K&R. It is running continuously, even when I type -1. I am using eclipse in fedora 17. whats wrong with this code? how would it terminate? Even CTRL+D not working to end it! #include<stdio.h> int main(void) { int c; c = getchar(); while(c != EOF) { putchar(c); c = getchar(); } return 0; } 回答1: It is running continuously, even when I type -1 On Unix you need to type Ctrl-D instead to signal end of file. As Mooing Duck points out, this seems to be a bug in Eclipse. 回答2: Send

Return value of ifstream.peek() when it reaches the end of the file

余生颓废 提交于 2019-12-10 18:41:40
问题 I was looking at this article on Cplusplus.com, http://www.cplusplus.com/reference/iostream/istream/peek/ I'm still not sure what peek() returns if it reaches the end of the file. In my code, a part of the program is supposed to run as long as this statement is true (sourcefile.peek() != EOF) where sourcefile is my ifstream. However, it never stops looping, even though it has reached the end of the file. Does EOF not mean "End of File"? Or was I using it wrong? 回答1: Consulting the Standard,

How to send EOF to a process in Java?

有些话、适合烂在心里 提交于 2019-12-10 15:53:31
问题 I want to run groff in a Java program. The input comes from a string. In real command line, we will terminate the input by ^D in Linux/Mac. So how to send this terminator in Java program? String usage += ".Dd \\[year]\n"+ ".Dt test 1\n"+ ".Os\n"+ ".Sh test\n"+ "^D\n"; // <--- EOF here? Process groff = Runtime.getRuntime().exec("groff -mandoc -T ascii -"); groff.getOutputStream().write(usage.getBytes()); byte[] buffer = new byte[1024]; groff.getInputStream().read(buffer); String s = new String

Send a EOF in a pipe without closing it

若如初见. 提交于 2019-12-10 14:59:56
问题 I am writing an app which uses GnuPlot for ploting data. Instead of using text format to comunicate both programs though a pipe (it is slow because of the vprintf() and the big amount of data being passed) I decided to use "binary" format. The problem is that in binary format GnuPlot expects a EOF (Ctrl+D) to end the transmission and plot the data. This is easy in UNIX console mode. Just pressing Ctrl+D will end the data input, plot the data AND mantain the console open waiting for more

Why isEOF doesn't work?

送分小仙女□ 提交于 2019-12-10 10:46:03
问题 Here is minimal complete example: import Control.Monad import System.IO loop :: IO () loop = do line <- getLine putStrLn line eof <- isEOF unless eof loop main = loop This program is supposed to read a line, print it out, stop if there is 'end of file' character in stdin . It doesn't leave the loop at all. If I put eof <- isEOF before putStrLn line the program behaves very strange (try it!). I cannot get it at all: how putStrLn can possibly affect input stream and why doesn't the program

C# - Stream/FileStream EOF

给你一囗甜甜゛ 提交于 2019-12-10 03:41:45
问题 Is anyone familiar with a way to find out you're at the end of the file? I'm using BinaryReader and tried PeekChar - but it throws an exception. Any other suggestions? Thanks. 回答1: From a Stream , if you Read(buffer, offset, count) you'll get a non-positive result, and if you Peek() you'll get a negative result. With a BinaryReader , the documentation suggests that PeekChar() should return negative: Return Value Type: System.Int32 The next available character, or -1 if no more characters are

End of file NullPointerException

戏子无情 提交于 2019-12-10 01:59:03
问题 What I wanted is to reach EOF by typing Ctrl + z from command line with BufferedReader reading from console. The following code does so. But the problem is, it issues a NullPointerException after reaching EOF . Is there a way to skip this exception? Or more precisely, what is the proper way of reaching EOF with BufferedReader reading from console? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class EOF { public static void main(String args[]) {

Linux - check if there is an empty line at the end of a file [duplicate]

故事扮演 提交于 2019-12-09 05:50:55
问题 This question already has answers here : How to detect file ends in newline? (6 answers) Closed last year . NOTE: this question used to be worded differently, using “with/out newline” instead of “with/out empty line” I have two files, one with an empty line and one without: File: text_without_empty_line $root@kali:/home#cat text_without_empty_line This is a Testfile This file does not contain an empty line at the end $root@kali:/home# File: text_with_empty_line $root@kali:/home#cat text_with

Can read(2) return zero when not at EOF?

女生的网名这么多〃 提交于 2019-12-08 16:37:50
问题 According to the man page for read(2), it only returns zero when EOF is reached. However, It appears this is incorrect and that it may sometimes return zero, perhaps because the file is not ready to be read yet? Should I call select() to see if it is ready before reading a file from disk? Note that nBytes is: 1,445,888 Some sample code: fd_set readFdSet; timeval timeOutTv; timeOutTv.tv_sec = 0; timeOutTv.tv_usec = 0; // Let's see if we'll block on the read. FD_ZERO(&readFdSet); FD_SET(fd,