Questions tagged [stdin]

Standard input (stdin, file descriptor 0) is the input stream to a program.

3861 questions
49
votes
3 answers

Scanf/Printf double variable C

Let's say I have this following bit of code in C: double var; scanf("%lf", &var); printf("%lf", var); printf("%f", var); It reads from stdin variable 'var' and then prints twice in stdout 'var'. I understand that's how you read a double variable…
Dragos Rizescu
  • 3,380
  • 5
  • 31
  • 42
49
votes
2 answers

Reading from stdin

What are the possible ways for reading user input using read() system call in Unix. How can we read from stdin byte by byte using read()?
Bunny Bunny
  • 745
  • 2
  • 6
  • 9
46
votes
6 answers

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…
Roman
  • 124,451
  • 167
  • 349
  • 456
46
votes
7 answers

How to make a bash function which can read from standard input?

I have some scripts that work with parameters, they work just fine but i would like them to be able to read from stdin, from a pipe for example, an example, suppose this is called read: #!/bin/bash function read() { echo $* } read $* Now this…
JBoy
  • 5,398
  • 13
  • 61
  • 101
45
votes
1 answer

Python 3: How to specify stdin encoding

While porting code from Python 2 to Python 3, I run into this problem when reading UTF-8 text from standard input. In Python 2, this works fine: for line in sys.stdin: ... But Python 3 expects ASCII from sys.stdin, and if there are non-ASCII…
Seppo Enarvi
  • 3,219
  • 3
  • 32
  • 25
44
votes
4 answers

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:…
Dave Kirby
  • 25,806
  • 5
  • 67
  • 84
43
votes
1 answer

What are the differences between readable and data event of process.stdin stream?

say I have process.stdin.setEncoding('utf8'); var myString = ''; What are the differences between process.stdin.on('readable', function() { myString += process.stdin.read(); }); and process.stdin.on('data', function(chunk) { myString +=…
stevemao
  • 1,423
  • 1
  • 16
  • 29
41
votes
2 answers

What is the difference between STDIN and $stdin in Ruby?

Ruby has two ways of referring to the standard input: The STDIN constant , and the $stdin global variable. Aside from the fact that I can assign a different IO object to $stdin because it's not a constant (e.g. before forking to redirect IO in my…
Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
39
votes
4 answers

Read stdin stream in a batch file

Is it possible to use a piped stdin stream inside a batch file? I want to be able to redirect the output of one command into my batch file process.bat list so: C:\>someOtherProgram.exe | process.bat My first attempt looked like: echo…
m0tive
  • 2,796
  • 1
  • 22
  • 36
39
votes
8 answers

How to pipe input to sublimetext on linux?

How do I receive text from stdin into sublimetext editor? With vim it works like this: echo "potato potato potato" | vim - The same thing works with gedit, creating a new document with the contents. Sublimetext seems to just start editing a file…
wim
  • 338,267
  • 99
  • 616
  • 750
38
votes
7 answers

How to feed mysql queries from bash

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…
tirithen
  • 3,219
  • 11
  • 41
  • 65
37
votes
8 answers

How to make ssh receive the password from stdin

How can you make SSH read the password from stdin, which it doesn't do by default?
olamundo
  • 23,991
  • 34
  • 108
  • 149
36
votes
7 answers

Read a character from standard input in Go (without pressing Enter)

I want my app to show: press any key to exit ... And to exit when I press any key. How can I achieve this? Note: I have googled but all of what I've found needed to press Enter at the end. I want something like Console.ReadKey() in C#. I am running…
Kaveh Shahbazian
  • 13,088
  • 13
  • 80
  • 139
35
votes
6 answers

What does sys.stdin read?

I get how to open files, and then use Python's pre built in functions with them. But how does sys.stdin work? for something in sys.stdin: some stuff here lines = sys.stdin.readlines() What's the difference between the above two different uses…
Vimzy
  • 1,871
  • 8
  • 30
  • 56
34
votes
4 answers

Standard input and output units in Fortran 90?

How can I read and write to the standard input, output and error streams stdin, stdout and stderr in Fortran? I've heard writing to stderr, for example, used to be write(5, fmt=...), with 5 the unit for stderr, and I know the way to write to stdout…
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173