stdin

How to read lines from stdin (*in*) in clojure

て烟熏妆下的殇ゞ 提交于 2019-12-02 17:27:04
I am writing my first clojure program, and want to read lines from stdin. When I try this: (doall (map #(println %) (line-seq *in*))) I get this exception: Exception in thread "main" java.lang.ClassCastException: clojure.lang.LineNumberingPushbackReader cannot be cast to java.io.BufferedReader (test.clj:0) I get the same results in version 1.0 and 1.1 So how do I convert *in* into a seq I can iterate over? I would have thought that this is common enough that *in* itself would be iterable, but that does not work either - if I try to use it directly I get: java.lang.IllegalArgumentException: Don

Fastest way for line-by-line reading STDIN?

你说的曾经没有我的故事 提交于 2019-12-02 17:13:39
I'm looking for the most time-efficient way to read STDIN line-by-line. The first line is the number of conditions to test. All the following lines are conditions (strings) with a maximum of 100 000 characters. I have already tried the following (plus result for 4 times 90 000 characters: Scanner with a while-loop (7255 ms) Scanner sc = new Scanner(System.in); int numberOfLines = Integer.parseInt(sc.nextLine()); long start = 0; int i = 1; while (i<=numberOfLines){ start = System.currentTimeMillis(); sc.nextLine(); Debug.println((System.currentTimeMillis()-start) + "ms for scanner while"); i++;

Standard Input for Unsigned Character

删除回忆录丶 提交于 2019-12-02 13:42:32
I am trying to send unsigned characters through a program, and I would like to be able to get the numbers through standard input (ie std::cin). For example when I type 2 I would like it send ☻ (unsigned char 2). when I use the code: std::cout << "Enter values: "; { unsigned char d; unsigned char e = 2; std::cin >> d; WriteFile(file, &d, 1, &written, NULL); std::cout << "d= " << d << "\n"; std::cout << "e= " << e; } I get Enter values: 2 d=2 e=☻ Can anyone tell me why d is being interpreted Incorrectly as unsigned char 50 while e is being interpreted correctly as unsigned char 2? And of course

Read all standard input into a Java byte array

故事扮演 提交于 2019-12-02 13:11:52
问题 What's the simplest way in modern Java (using only the standard libraries) to read all of standard input until EOF into a byte array, preferably without having to provide that array oneself? The stdin data is binary stuff and doesn't come from a file. I.e. something like Ruby's foo = $stdin.read The only partial solution I could think of was along the lines of byte[] buf = new byte[1000000]; int b; int i = 0; while (true) { b = System.in.read(); if (b == -1) break; buf[i++] = (byte) b; } byte

stdin stdout python: how to reuse the same input file twice?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 12:54:43
问题 I am quite new to Python and even newer to stdin stdout method. Nevertheless I need to make my script usable for UNIX commands, in order to make it possible for example to process 2 input files at once with my script. This script works perfectly well with command line arguments: newlist = [] def f1() .... def f2(input_file): vol_id = sys.argv[3] for line in input_file: if ... : line = line.replace('abc','def') line = line.replace('id', 'id'+vol_id) .... newlist.append(line) return newlist def

C++: Infinite loop with a simple menu selection

雨燕双飞 提交于 2019-12-02 12:20:18
The script I am working on is over a page long, so I am going to link it (one simple file): http://pastebin.com/7BVHmQGp I apologize for that. My problem is I get into an infinite loop in my code, for example after I select 1 or 2 for encrypting/unencrypting it lets me enter the word, and when I next enter the "shift" for the cipher it runs an infinite loop of the menu. I had tried for so many hours to debug this, I thought it was a problem with cin , for example when you enter an invalid choice it just throws an infinite loop/ What seems to cause the infininte loops? I think you should be

C - Reading from stdin as characters are typed

让人想犯罪 __ 提交于 2019-12-02 11:48:20
问题 How do I fill an 80-character buffer with characters as they are being entered or until the carriage return key is pressed, or the buffer is full, whichever occurs first. I've looked into a lot of different ways, but enter has to be pressed then the input char* gets cut off at 80.. Thanks. 回答1: If you really want the characters "as they are entered", you cannot use C io. You have to do it the unix way. (or windows way) #include <stdio.h> #include <unistd.h> #include <termios.h> int main() {

Twisted Python: Cannot write to a running spawned process

我的未来我决定 提交于 2019-12-02 10:37:56
问题 My question is, after spawning a process, the child process is looping to get data from its stdin. I would like to write new data to it using either Echo.Process.pipes[0].write(data) or Echo.Process.writeToChild(0,data), but both do not work. Would someone explain what's going on? Or how do I go around this problem? This is the error I got: --- <exception caught here> --- File "/usr/local/encap/python-2.6.4/lib/python2.6/site-packages/Twisted-9.0.0-py2.6-linux-x86_64.egg/twisted/internet

C - getchar() in a loop?

别来无恙 提交于 2019-12-02 10:06:24
How I can use getchar() in a loop? Now I have... for (p=0; p<n_players; p++) { ... fflush(stdin); getchar(); } But it doesn't work... if n_players is 3, it execute getchar 2 times only at the end... for (p=0; p<n_players; p++) { blank_start(); ascii_art_title(); printf("%s, tocca a te...\n",player_info[p].player_name); srand(time(NULL)); random_speed = MIN_WHEEL_SPEED + rand()%MAX_WHEEL_SPEED; move_wheel_pointer(random_speed, &pointer); if (player_points(&wheel[pointer]) == 0){ player_info[p].points = wheel[pointer]; } else { player_info[p].points = 0; } printf("\nGuadagni %d punti...\n"

'git am < MyFix.patch' command error in Powershell

情到浓时终转凉″ 提交于 2019-12-02 09:49:25
问题 How do we get this command to run on Powershell with out error : The '<' operator is reserved for future use. C:\Users\Me\my-git-repo > git am < MyFix.patch The '<' operator is reserved for future use. At line:1 char:9 + git am < <<<< MyFix.patch + CategoryInfo : ParserError: (<:OperatorToken) [],.. + FullyQualifiedErrorId : RedirectionNotSupported 回答1: Use either: Get-Content MyFix.patch | git am or: cmd /c 'git am < MyFix.patch' Both should work equally well. Windows Powershell simply doesn