stdin

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

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 i...

Ruby Switch Between File and Standard Input

How would you create a variable that could be read. It would read from a certain file if it exists, otherwise it would read from standard input. Something like: input = File.open("file.txt") || in This doesn't work, but I think this should be done pretty often, but I can't find a nice way to do it. ...

How to redirect stdin from my app to another knowing its PID (C,in windows)

I have a script vbs wich redirect some data to the stdin of myApp (written in C in Windows). If myApp was already launched before myApp finds the PID of the first myApp session and redirects the input received via stdin to the stdin of the first session of myApp which handles the stdin. So when myApp receives a stdin and no other instanc...

Does reading from stdin flush stdout?

stdout is line-buffered when connected to a terminal, but I remember reading somewhere that reading (at least from stdin) will automatically flush stdout. All C implementations that I have used have done this, but I can't find it in the standard now. It does make sense that it works that way, otherwise code like this: printf("Type some...

getpasswd functionality in Go?

Would like to be able to take password entry from the stdin console, but, of course, without echoing what the user types. Is there something comparable to getpasswd functionality in Go? (Google's Go language) I tried using syscall.Read, but it echoes what is typed. ...

Python, Stdin and List: accepting only positive numbers?

Do not code like this. Please, read the hints by the accepted answer. I tried to remove the junk but I coundn't. Code import sys a = [] i=0 for line in sys.stdin: try: n = float(line) a.append(n) i+=1 except ValueError: print 'Number please!'; ...

Why is windows select() not always notifying thread B's select() when thread A closes its end of a socket pair?

Hi all, A situation I have under Windows XP (SP3) has been driving me nuts, and I'm reaching the end of my tether, so maybe someone can provide some inspiration. I have a C++ networking program (non-GUI). This program is built to compile and run under Windows, MacOS/X, and Linux, so it uses select() and non-blocking I/O as the basis f...

Why do I have to press Ctrl+D twice to close stdin?

I have the following python script that reads numbers and outputs an error if the input is not a number. import fileinput import sys for line in (txt.strip() for txt in fileinput.input()): if not line.isdigit(): sys.stderr.write("ERROR: not a number: %s\n" % line) If I get the input from stdin, I have to press Ctrl+D twice...

I am not able to flush stdin.

How to flush the stdin?? Why is it not working in the following code snippet? #include <string.h> #include <stdio.h> #include <malloc.h> #include <fcntl.h> int main() { int i=0,j=0, sat; char arg[256]; char * argq; argq = malloc(sizeof(char)*10); printf("Input the line\n"); i=read(0, a...

reading unknown number of integers from stdin (C)

I need to read an input file like : 1 19 20 41 23 2 41 52 43 3 90 91 941 4 512 5 6 51 61 each odd line is an integer each even line is unknown number of integers it is very easy in C++ while( cin >> k ){ ............ } Im not so used to C language so I couldnt make it in C. any ways to do it? ...

How to select on STDIN_FILENO ignoring signals?

Please check the following code #include <stdio.h> #include <string.h> #include <stdlib.h> #include <termios.h> #include <unistd.h> #include <sys/types.h> #include <signal.h> #include <sys/time.h> #include <time.h> #define CLOCKID CLOCK_REALTIME #define SIG SIGRTMIN int reset = 0; void changemode(int); int kbhit(void); int pfds[2]; s...

How to go about reading a string and then format it in C?

How would I go about reading a string from stdin and formatting as such to stdout? For example: If I receive someone's name: John Doe 03 17 I want to create user name for him as such: jd0317 Although it can change to for someone with a middle name: Jane B. Doe 05 18 Then it would be: jbd0518 I assume you would read the line and then...

How to read from stdin or from a file if no data is piped in Python ?

Hi, I have a CLI script and want him to read data from a file. It should be able to read it in two ways : cat data.txt | ./my_script.py ./my_script.py data.txt A bit like grep, for example. What I know: sys.argv and optparse let me read any args and options easily. sys.stdin let me read data piped in fileinput make the full proce...

Why do I get the "Unhandled exception type IOException"?

I have the following simple code: import java.io.*; class IO { public static void main(String[] args) { BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { System.out.println(userInput); } ...

Why does supplying stdin to subprocess.Popen cause what is written to stdout to change?

I'm using Python's subprocess.Popen to perform some FTP using the binary client of the host operating system. I can't use ftplib or any other library for various reasons. The behavior of the binary seems to change if I attach a stdin handler to the Popen instance. For example, using XP's ftp client, which accepts a text file of commands...

How to pass variables as stdin into command line from PHP

I am trying to write a PHP script that uses the pdftk app to merge an XFDF with a PDF form and output the merged PDF to the user. According to the pdftk documentation, I can pass the form data in via stdin and have the PDF output to the stdout stream. The normal, file-not-stream way to use pdftk from the command line is: pdftk blankform...

What is a good way to read in text?

Hello! In my sms-script I read in the text to send with this subroutine: my $input = input( "Enter the input: " ); sub input { my $arg = shift; print $arg if $arg; print "\n "; chomp( my $in = <> ); return $in; } This way I can correct errors only through canceling all until I reach the error and this only in the ...

D (Tango) Read all standard input and assign it to a string

In the D language how I can read all standard input and assign it to a string (with Tango library) ? ...

Is stdin limited in length?

Are there any stdin input length limitations (in amount of input or input speed)? ...

Is cin a proper file object?

As in, can I pass cin to any function that accepts an ifstream object? ...