stdin

How can I get user input without receiving an “Unsed Variable” warning?

混江龙づ霸主 提交于 2021-01-28 21:03:51
问题 I'm taking a look at Rust and decided to build a small program that takes a user's input and prints it, but also want to do some math stuff with it for practice. Currently, this is how I am taking user input: let mut number = String::new(); let input = io::stdin().read_line(&mut number) .ok() .expect("Failed to read line"); println!("You entered {}", number); However, although I do get the correct input this way, Cargo gives me the following warning: src/main.rs:10:9: 10:14 warning: unused

exit from STDIN from bash script when the user want to close it

有些话、适合烂在心里 提交于 2021-01-28 07:47:55
问题 I'm automating the file creation from a bash script. I generated a file rc_notes.txt which has commit messages from two tags and want to re-write that in a new file as rc_device.txt . I want the user to write the customer release notes and exit from the BASH STDIN that I prompt in the terminal. The problem in my script is I'm not able to trap the close of file. Wondering how to do. I don't want to trap the close signal. I want to enter magic string example: Done or some string that triggers

How do I read data from stdin to gnuplot and plot same data twice

痴心易碎 提交于 2021-01-28 02:58:17
问题 I have a program that generates data with a couple of input arguments and spits it out to stdout, I pipe this data to gnuplot and plot it (in my case I don't have an intermediate file): $ cat sample_data.dat | gnuplot plot_script.gp sample_data.dat: 0 0.5000 1 0.9225 2 0.2638 3 0.7166 4 0.7492 plot_script.gp #!/usr/bin/gnuplot set terminal wxt size 700,524 enhanced font 'Verdana,10' persist set style line 1 lc rgb '#0060ad' pt 7 lt 1 lw 0.5 # circle blue thin line set style line 2 lc rgb '

ssh in bash script exits loop [duplicate]

。_饼干妹妹 提交于 2021-01-28 01:44:56
问题 This question already has answers here : While loop stops reading after the first line in Bash (4 answers) Closed 3 years ago . I am trying to run some commands on few remote hosts. I have the list of their ips in a file ips.txt (one ip per line). #!/bin/bash while IFS= read -r wip; do echo $wip ssh root@$wip "pkill pgm; cd /root/pgm; nohup ./pgm > /dev/null 2>&1 &" echo "$wip end" done < ips.txt I am running the above script. But the problem is after reading the first ip the loop exits. But

Do 'cat foo.txt | my_cmd' and 'my_cmd < foo.txt' accomplish the same thing?

≯℡__Kan透↙ 提交于 2021-01-28 01:24:29
问题 This question helped me understand the difference between redirection and piping, but the examples focus on redirecting STDOUT ( echo foo > bar.txt ) and piping STDIN ( ls | grep foo ). It would seem to me that any command that could be written my_command < file.txt could also be written cat file.txt | my_command . In what situations are STDIN redirection necessary? Apart from the fact that using cat spawns an extra process and is less efficient than redirecting STDIN, are there situations in

Process never ends when using 'process.stdin.once'

放肆的年华 提交于 2021-01-27 14:30:46
问题 In my node script, I am waiting for the user to press enter at some point: console.log("Press enter to continue..."); await new Promise(function(resolve, reject) { process.stdin.once("data", function(data) { resolve(); }); }); The script runs fine, and continues only after the user has pressed enter. But at the end of the execution, the process does not terminate. Instead, it seems to be just pending for user input (i.e., a newline is printed every time I press enter). I'm pretty sure that

How do I discard user input delivered during sleep function?

喜你入骨 提交于 2021-01-27 12:14:05
问题 I'm trying to create a game using the terminal. I ask if the player is ready and then make a countdown with the code down below. The problem is that all input the user makes is added to the next input query the program makes. I'm looking for a way to discard the previous input or block it entirely during this function. I could do a getchar loop, but that would need user input after the countdown (pressing enter) which I don't want. void countdown(void){ printf("5\n"); sleep(1); printf("4\n");

Java command line “shell” with auto-complete

两盒软妹~` 提交于 2021-01-22 07:00:28
问题 I need to create a Java command line to that will be invoked remotely on a server. It will need to: Read "lines" of text from the user. Recognise if the user presses the "tab" key to facilitate auto-complete. Recognise if the user presses the "up/down" keys for history. Before I go off and roll my own, Is anyone aware of a Java library that might facilitate all or part of this? i.e. From the command line in ssh it might look like this: bob> java -jar MyTool.jar MyTool Started. Please enter

Java command line “shell” with auto-complete

喜欢而已 提交于 2021-01-22 06:58:14
问题 I need to create a Java command line to that will be invoked remotely on a server. It will need to: Read "lines" of text from the user. Recognise if the user presses the "tab" key to facilitate auto-complete. Recognise if the user presses the "up/down" keys for history. Before I go off and roll my own, Is anyone aware of a Java library that might facilitate all or part of this? i.e. From the command line in ssh it might look like this: bob> java -jar MyTool.jar MyTool Started. Please enter

Smalltalk (Pharo) How to interface with the user simply

南笙酒味 提交于 2021-01-21 08:29:35
问题 I stumbled upon Smalltalk and further downloaded Pharo, because it was recommended. My first impression is very positive. I wanted to port some simple programs I have written in C++ (my main language), so I can get a feel for Smalltalk. However, I realized I can't find a simple way to just get some input from the user, e.g. I want to create a console calculator with a REPL loop, but I can't find a way to do this in Pharo. I don't want a gui with buttons, because that is just slow and