stdin

How do I redirect stdin from a shell script to a command in the shell script?

How do I redirect stdin from a shell script to a command in the shell script? I am trying to pass the stdin to a java System.in stream. I want to replace find . -type f | $JAVA_HOME/bin/java com.domain.BatchProcess with find . -type f | ./batch.sh ...

[ruby] How to convert STDIN contents to an array?

I've got a file INPUT that has the following contents: 123\n 456\n 789 I want to run my script like so: script.rb < INPUT and have it convert the contents of the INPUT file to an array, splitting on the new line character. So, I'd having something like myArray = [123,456,789]. Here's what I've tried to do and am not having much luck: ...

PHP standard input?

I know PHP is usually used for web development, where there is no standard input, but PHP claims to be usable as a general-purpose scripting language, if you do follow it's funky web-based conventions. I know that PHP prints to stdout (or whatever you want to call it) with print and echo, which is simple enough, but I'm wondering how a P...

Setting non-canonical mode on stdin with Ruby

I'm playing around with making a simple terminal-based game with Ruby, and I'm currently trying to come up with a way of reading input from the terminal. So far I've been using gets, but I'd like to have the game react instantly without requiring a newline (so you don't need to press a key, THEN enter). I've figured out I need to put t...

`tee` command equivalent for *input* ?

The unix tee command splits the standard input to stdout AND a file. What I need is something that works the other way around, merging several inputs to one output - I need to concatenate the stdout of two (or more) commands. Not sure what the semantics of this app should be - let's suppose each argument is a complete command. Exampl...

ksh: how to probe stdin?

I want my ksh script to have different behaviors depending on whether there is something incoming through stdin or not: (1) cat file.txt | ./script.ksh (then do "cat <&0 >./tmp.dat" and process tmp.dat) vs. (2) ./script.ksh (then process $1 which must be a readable regular file) Checking for stdin to see if it is a terminal[ -t 0...

redirect the stdin to come from a different terminal using Bash

Hello. I'm wondering how one would go about redirecting the stdin of a script from the current xterm session i.e. /dev/pts/0 to one that is also running i.e /dev/pts/1 using bash? I have a bash script that opens 3 xterm windows and I want to get input from only one of those windows and I cannot figure out how to do it. Any help is apprec...

How do I read from standard input in a WPF application?

I'm trying to figure out how to read from the standard input stream of my own WPF application but I can't find a way to get the stream. The standard way to do it, Console.ReadLine() returns Null(Nothing) immediately. I'm assuming because it's not a console application and no console window is open. How can I read from standard input ...

Ignoring EOF on std::cin in C++

I have an application that implements an interactive shell, similar to how the Python console / irb works. The problem now is that if the user accidentally hits ^D EOF is issued and my getline() call returns an empty string which i treat as "no input" and display the prompt again. This then results in an endless loop that prints the pr...

How do I iterate over all lines of files passed on the commandline in Python?

I usually do this in Perl: whatever.pl while(<>) { #do whatever; } then cat foo.txt | whatever.pl Now, I want to do this in Python. I tried sys.stdin but I have no idea how to do as I have done in Perl. How can I read the input? Thanks. EDIT: Thanks, I like every single solution. ...

Read a line of input faster than fgets?

I'm writing a program where performance is quite important, but not critical. Currently I am reading in text from a FILE* line by line and I use fgets to obtain each line. After using some performance tools, I've found that 20% to 30% of the time my application is running, it is inside fgets. Are there faster ways to get a line of text?...

Why did my use of the read command not do what I expected?

I did some havoc on my computer, when I played with the commands suggested by vezult [1]. I expected the one-liner to ask file-names to be removed. However, it immediately removed my files in a folder: > find ./ -type f | while read x; do rm "$x"; done I expected it to wait for my typing of stdin:s [2]. I cannot understand its action....

gdb won't accept stdin redirection in emacs

I'm trying to debug a program using gdb mode in emacs. It was compiled with g++, and I'm using cygwin. My program takes one command line argument, and also takes input from stdin, which I redirect from a file, like this: program.exe inputFile.dat <otherInput.dat The problem is, gdb is sending the string "<otherInput.dat" as a comma...

Python equivalent of Perl's while (<>) {...}?

I write a lot of little scripts that process files on a line-by-line basis. In Perl, I use while (<>) { do stuff; } This is handy because it doesn't care where the input comes from (a file or stdin). In Python I use this if len(sys.argv) == 2: # there's a command line argument sys.stdin = file(sys.argv[1]) for line in sys.st...

Python cgi and stdin

I'm using pycurl to upload a file via put and python cgi script to receive the file on the server side. Essentially, the code on the server side is: while True: next = sys.stdin.read(4096) if not next: break #.... write the buffer This seems to work with text, but not binary files (I'm on windows). With binary files, t...

peek at input buffer, and flush extra characters in C

If I want to receive a one character input in C, how would I check to see if extra characters were sent, and if so, how would I clear that? Is there a function which acts like getc(stdin), but which doesn't prompt the user to enter a character, so I can just put while(getc(stdin)!=EOF);? Or a function to peek at the next character in th...

in windows, how to have non-blocking stdin that is a redirected pipe?

I have a Windows C program that gets its data through a redirected stdin pipe, sort of like this: ./some-data-generator | ./myprogram The problem is that I need to be able to read from stdin in a non-blocking manner. The reason for this is that (1) the input is a data stream and there is no EOF and (2) the program needs to be able to...

How to know when a Magnetic Card Reader is done.

2-Part question because I think I may know the answer to the first part: The existing solution was to set a timer on a form and read track by track for a few seconds. That doesn't seem too robust. My idea is to parse the card data and that way I'll know when I'm done. Unfortunately I just realized while writing this that I don't kno...

How to ignore arrow keys in C reading from stdin?

I'm reading from the standard input using the read() system call but there's a tiny thing that bothers me. I can't use the arrow keys... What I really wanted to do was to use arrow keys to go back and forth within the typed text but I think that's not that easy... So, what I at least want to do, is to ignore them. Right now, pressing an...

C# bi-directional IPC over stdin and stdout

How can I connect two C# processes so they can communicate with each other over stdin and stdout? Like this: Process A --> stdout A --> stdin B ---> Process B Process A <-- stdin A <-- stdout B <--- Process B ...