stdin

How to check if stdin is pending in TCL?

白昼怎懂夜的黑 提交于 2019-12-08 06:33:25
问题 Consider the following code: chan configure stdin -blocking false while { true } { chan gets stdin if { chan blocked stdin } { break } } Here at the last line of the loop chan blocked stdin returns true in either cases: when there is no more input available at stdin , and when there there is some input available at stdin , but it doesn't end with a newline character. I need to distinguish these two cases. How can I do that? chan pending input stdin also returns 0 in both cases. Here is the

Why does Bash always add a newline when expanding here strings?

被刻印的时光 ゝ 提交于 2019-12-08 06:04:01
问题 Having read the following description of this feature of Bash (excerpt from the man page): Here Strings A variant of here documents, the format is: <<<word The word is expanded and supplied to the command on its standard input. I expected that the interpretation of here strings is that Bash simply passes the contents of a variable directly on a command's standard input, unmodified. Following this logic, the lines [1] and [2] below would be effectively equivalent. [1]~$ printf foo | cat - <

File to socket adapter in python

空扰寡人 提交于 2019-12-08 05:16:11
问题 I want to use the asyncio library on Windows to read file-like objects (such as sys.stdin and serial ports). However, asyncio on Windows expects readable objects to be sockets. Is it possible to write an adapter class to wrap a file-like object with the API of a socket so that I could use stdin and serial ports with asyncio ? If so, please could you give an example because I've never used sockets before? 回答1: Short answer No and maybe yes. Long answer You can't just wrap a file-like object as

First fgets() call being skipped during input?

删除回忆录丶 提交于 2019-12-08 04:23:24
问题 I'm writing a program that can take computer specifics from the user in manual mode. However, I've run into a bit of a problem. In this code: char choice = getc(stdin); if (choice == 'y' || choice == 'Y') { config_file = fopen(config_file_loc, "w"); printf("%s", "Please enter the name of your distribution/OS: "); fgets(distro_str, MAX_STRLEN, stdin); fputs(distro_str, config_file); fputs("\n", config_file); printf("%s", "Please enter your architecture: "); fgets(arch_str, MAX_STRLEN, stdin);

Char Array and getline in C

ぃ、小莉子 提交于 2019-12-08 04:00:15
问题 int bytes_read; int rv; int nchars = 200; /*max possible number for the input of the user*/ size_t nbytes = nchars; /*size of chars in bytes*/ char *commands[2]; char *line = malloc(nbytes + 1); bytes_read = getline(&line, &nbytes, stdin); /*read line from stdin*/ if (bytes_read == -1) { printf("Read line error"); exit(-1); } else { if (line[strlen(line-1)] == '\n') { line[strlen(line-1)] = '\0'; /*change new line character in the end of the line of stdin*/ } } if (strcmp(line,"exit") == 0) {

How to avoid going to new line with stdin in Rust

我的梦境 提交于 2019-12-08 01:04:24
问题 I have this code: fn main() { let mut stdin = io::stdin(); let input = &mut String::new(); loop { input.clear(); print!("Your age: "); stdin.read_line(input); print!("{}", input); } } So when I input something, the programs returns "Your age:" plus my input. But when I run the program I don't want to write the input in a new line. To do something like that in Python, I can write: var = input("Your age: ") How can I avoid going to a new line? I'm sure it's simple but I really can't realize how

Prepend to stdin

拥有回忆 提交于 2019-12-08 00:08:14
问题 I've got an interactive command line program that we'll call program.exe. While it's running, I can type in a bunch of different commands that do different things. We'll call them: doA, doB, doC, and quit. Now, as it turns out, the first thing I want to do in program.exe is always doA. I'd like to save a few keystrokes and automatically have program.exe run the command doA upon startup. Unfortunately, I can't just pass "doA" on the command line because whoever created program.exe didn't

difference between communicate() and .stdin.write, .stdout.read or .stderr.read - python

谁说我不能喝 提交于 2019-12-07 17:49:12
问题 I wan to create a pipe between 3 commands: cat = subprocess.Popen("cat /etc/passwd", stdout=subprocess.PIPE) grep = subprocess.Popen("grep '<usernamr>'", stdin=cat.stdout, stdout=subprocess.PIPE) cut = subprocess.Popen("cut -f 3 -d ':'", stdin=grep.stdout, stdout=subprocess.PIPE) for line in cut.stdout: # process each line here But python documentation says: Use communicate() rather than .stdin.write , .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers

Use stdin from within R studio

旧城冷巷雨未停 提交于 2019-12-07 17:25:39
问题 When I try the following: f<-file("stdin") lines<-readLines(f) from within R-studio on Ubuntu I can input text but unable to terminate it. Ctr+C/D, random hitting keyboard won't help. It simply hangs I only found the followin so far How to input EOF in stdin in R? but no help there - had to kill R-studio. Anybody have explanation what is wrong? 回答1: Presumably, Rstudio is redirecting stdin, so that it cannot be properly accessed as "stdin" or "/dev/stdin" any longer. However, stdin() still

Redirecting Multiple stdins?

不羁的心 提交于 2019-12-07 14:31:51
问题 I have three files named One, Two, Three. One contains: 1 3 2 Two contains: 4 6 5 Three contains: 7 9 8 When I give the following command: $sort < One < Two < Three I get the output: 7 8 9 But when I give the following command: $sort One Two Three I get the ouput: 1 2 3 4 5 6 7 8 9 Can anyone please shed light on what exaclty is happening here? Why does the input from 1 and 2 not taken into consideration in the first command? 回答1: Your command is the same as: sort 0<1 0<2 0<3 (file descriptor