stdin

Is it possible to read characters from `io::stdin()` without caching input line-by-line?

徘徊边缘 提交于 2019-12-24 04:38:05
问题 This question refers to the stable Rust version 1.2.0 I just want to iterate over the characters in the standard input of my CLI application. It's perfectly possible to do read stdin 's read_line method into a temporary String instance and then iterate over it's chars() iterator. But I don't like this approach, as it allocates a totally unnecessary String object. Stdin trait's documentations implements Read trait, which has chars() iterator, but it is marked as unstable (and thus can't be

NodeJS Read stdin from background process

◇◆丶佛笑我妖孽 提交于 2019-12-24 03:26:10
问题 I have a node process running under Ubuntu 12.04 LTS as a service (it has a configuration file under /etc/init). The system runs on a headless x86 routerboard to which a barcode reader is connected. What I need to do is be able to read the input from the barcode reader (which behaves like a USB keyboard for all intents and purposes) so that it can be sent to a remote node for processing, but I'd like to avoid having to parse raw HID input. Right now I'm using node-hid but the solution is

TCL gets command with kind of -nohang option?

孤者浪人 提交于 2019-12-24 03:17:02
问题 Here is a code which just implements an interactive TCL session with command prompt MyShell > . puts -nonewline stdout "MyShell > " flush stdout catch { eval [gets stdin] } got if { $got ne "" } { puts stderr $got } This code prompts MyShell > at the terminal and waits for the enter button to be hit; while it is not hit the code does nothing. This is what the gets command does. What I need, is some alternative to the gets command, say coolget . The coolget command should not wait for the

How to read inputs from stdin and enforce an encoding?

孤者浪人 提交于 2019-12-24 02:18:57
问题 The goal is to continuously read from stdin and enforce utf8 in both Python2 and Python3. I've tried solutions from: Writing bytes to standard output in a way compatible with both, python2 and python3 Python 3: How to specify stdin encoding I've tried: #!/usr/bin/env python from __future__ import print_function, unicode_literals import io import sys # Supports Python2 read from stdin and Python3 read from stdin.buffer # https://stackoverflow.com/a/23932488/610569 user_input = getattr(sys

Portably opening a handle to stdin many times in a single session

对着背影说爱祢 提交于 2019-12-24 00:58:58
问题 Code: main = do putStrLn "4917 Microprocessor\nEnter the Machine Code to be run: " inp <- getContents putStrLn "The output of the Program is:" fState <- ((runStateT _4917) . construct . parse) inp args <- getArgs if elem "-v" args then putStrLn ("\nFinal state was: " ++ (show . snd) fState) else return () putStrLn "\n================================ RESTART ================================" main where parse xs = array (0,15) $ zip [0..15] $ take 16 $ map ((makeArbInt 4) . read) (words (filter

print delay with pexpect: select returning stdin when no data ready to read

拥有回忆 提交于 2019-12-24 00:52:22
问题 Using pexpect I'm running Python in a subprocess. When the program below is run, I have to hit a key before the >>> prompt is displayed. I previously was using a naive version of pexpect, but switched hoping this would fix the problem. In this naive version, the problem was that select.select() returned stdin as ready to read when in fact it wasn't, as a blocking read on stdin was attempted, blocking the program until I hit a key. I suspect the same thing is happening here. How do I prevent

reading large lists through stdin in C

风流意气都作罢 提交于 2019-12-24 00:44:17
问题 If my program is going to have large lists of numbers passed in through stdin , what would be the most efficient way of reading this in? The input I'm going to be passing into the program is going to be of the following format: 3,5;6,7;8,9;11,4;; I need to process the input so that I can use the numbers between the colons (i.e I want to be able to use 3 and 5, 6 and 7 etc etc). The ;; indicates that it is the end of the line. I was thinking of using a buffered reader to read entire lines and

A simple yes/no script yields weird behavior

ぐ巨炮叔叔 提交于 2019-12-23 22:27:02
问题 I am trying to implement a simple yes/no script. A function runs, then the user is prompt to input whether or not to run it again. If the user inputs "y", then the procedure should repeat. If the user inputs "n", then the procedure should terminate. If neither, then the question should repeat. Here is my code: function func(i) { console.log(i); ask(i + 1); } function ask(i) { process.stdout.write("again (y/n)?"); process.stdin.on("data", function(data) { process.stdin.end(); if (data.toString

Unbuffered non-blocking keyboard input on command line

☆樱花仙子☆ 提交于 2019-12-23 22:07:58
问题 I want to capture "all" keyboard input on the command line immediately (without waiting for a new line) in a non-blocking way. This question demonstrates how you can read from stdin in a non-blocking way using select() . This is how it works: while True: if select.select([sys.stdin], [], [], 0)[0] == [sys.stdin]: print(sys.stdin.read(1)) ... do other stuff ... Unfortunately you only get results after pressing RETURN . My first guess was that stdin is just line buffered so after reading this

WIndows: subprocess making new console window, losing stdin/out

六月ゝ 毕业季﹏ 提交于 2019-12-23 18:53:27
问题 I'm using Windows Vista and Python 2.7.2, but answers needn't be in Python. So I can start and interact with a subprocesses stdin/stdout normally (using python), for command-line programs such as `dir'. - however - the program I now want to call likes to make a new console window for itself on Windows (not curses), with new handles, even when run from a pre-existing cmd.exe window. (Odd, as it's the "remote control" interface of VLC.) Is there any way of either: getting the handles for the