stdin

how to redirect stdin to java Runtime.exec?

喜夏-厌秋 提交于 2019-11-28 01:33:59
问题 I want to execute some sql scripts using Java's Runtime.exec method. I intend to invoke mysql.exe / mysql.sh and redirect the script file to this process. From the command prompt I can run the command <mysqInstallDir\/bin\mysql.exe -u <userName> -p <password> < scripts\create_tables.sql I can invoke mysql.exe using Runtime.exec but how do I redirect data from sql file to mysql.exe ? I read the article in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4 and used the

Ant exec task: How can I read input from console stdin?

我与影子孤独终老i 提交于 2019-11-28 01:04:52
问题 I have a call to Ant exec task that needs to accept input from console stdin. Unfortunately, I cannot find a way to do this. The stdin filehandle seems closed to console input at runtime. It is possible to specify input using attributes input and inputstring . However, I need to prompt for user input at the console. How can I do this? 回答1: From the documentation of the task: Note that you cannot interact with the forked program, the only way to send input to it is via the input and

How to clear stdin before getting new input?

独自空忆成欢 提交于 2019-11-28 00:52:58
I have read about 5-10 different advices how to clear stdin, but none of them suits my needs. The thing is that fflush(stdin) worked perfectly at my computer, but unfortunately it doesn't seem to work everywhere, so I need something with the same functionality. Every other way I tried clears stdin when it is not empty but requires user input when stdin IS empty, which means it requires input in a moment I dont want to get any (+ it discards it anyway). The question is: Can I somehow make sure, that stdin IS empty before I require user input? (and if not, THEN and only then clear it somehow?)

C, flushing stdin

天涯浪子 提交于 2019-11-28 00:21:52
i have a problem with the use of fgets. The loop is supposed to read a line of max. 19 characters, analyze this char array and then wait for next input. The problem is that if the line entered exeeds 19 characters, fgets will fill str with the remaining characters untill Ctrl-D or newline is entered, thus initiating a new loop without new input. The input (stdin) should in some way be flushed after 19 characters are read, so the loop can start with a clean slate. Anyone have a solution to this? char str[20]; while((fgets(str, 20, stdin) != NULL)) { puts(str); //monitoring str if(str[0] == 'q')

MongoDB shell: reading a line from the console

久未见 提交于 2019-11-28 00:18:14
问题 Is there a way to read a line from the Mongo shell? readline() is not defined and neither is system.stdin . I need to do this in interactive mode, as opposed to feeding input to a script executed by the MongoDB shell. 回答1: Per @Stennie's comment, this is not possible right now. 回答2: Officially, this is not possible in Mongo shell. Unofficially, yes it is possible. There is one small hack you can use to read user input. Mongo shell among many undocumented functions, contains one function named

Python in raw mode stdin print adds spaces

偶尔善良 提交于 2019-11-28 00:14:56
问题 I needed to switch the standard input to non-buffered mode in Python, so that I can read single characters off it. I managed to get it working, but now the standard output is broken: somehow it seems like after the newline character, some space characters are emitted, zero on the first line, 3 on the second, 6 on the third, etc, like this: ASD ASD ASD Operating system is Ubuntu Linux 12.04, 64-bit edition, Python version is 3.2.3. How can I rid myself from this behavior? Below is the code I

End of File in stdin

我怕爱的太早我们不能终老 提交于 2019-11-27 23:44:46
A question about this has been asked here End of File (EOF) in C but it still doesn't completely solve my problem. EOF makes sense to me in any datastream which is not stdin , for example if I have some data.txt file, fgetc() will read all the chars and come to the end of file and return -1 . What I don't understand is the concept of EOF in stdin . If I use getchar() , it will wait for me to enter something, so if there is NOTHING written, End of File, ( EOF ) is not returned automatically? So is it that only the user can invoke EOF in stdin by pressing Ctrl + Z ? If so then what are some of

Use of undefined constant STDIN - assumed 'STDIN' in C:\\wamp\\www\\study\\sayHello.php on line 5

孤人 提交于 2019-11-27 23:16:19
I want to Learn php & mySQL and I purchased a book (php&mySql: the missing manuals 2edition) I installed Wampserver2.4 on win8 64bit machine. Server Configuration Apache Version : 2.4.4 PHP Version : 5.4.12 in first lesson i got this error :( Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\wamp\www\study\sayHello.php on line 5 this is the php code on file "sayHello.php" <?php echo "Hello there. So I hear you're learning to be a PHP programmer!\n"; echo "Why don't you type in your name for me:\n"; $name = trim(fgets(STDIN)); echo "\nThanks, " . $name . ", it's really nice to

Understanding stdin stdout stderr [duplicate]

孤街醉人 提交于 2019-11-27 21:16:29
This question already has an answer here: Confused about stdin, stdout and stderr? 10 answers I'm trying to understand stdin stdout and stderr . I see them used in people's code all the time and I can't understand exactly what they are. I am assuming that they have something to do with input/output but have been searching for an explanation online and can't find one. Does anybody know of a good link with an explanation or if it is simple enough to explain it would be a great help to me. Since I am learning Python 3, examples in that would be helpful. sys.stdin sys.stdout sys.stderr File

How to feed mysql queries from bash

倖福魔咒の 提交于 2019-11-27 21:06:29
I'm trying to make a bash script that creates a mysql user and database but I can't find a way to feed the sql into mysql, I'm trying with this format: mysql < echo "query" But that is not working, see the example below: mysql --host=localhost --user=user --password=password < echo "CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'jakdJxct8W'; CREATE DATABASE IF NOT EXISTS 'testuser_dev' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; GRANT ALL PRIVILEGES ON 'testuser_dev' . * TO 'testuser'@'localhost'; CREATE DATABASE IF NOT EXISTS 'testuser_qa' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;