stdin

C - Using poll to multiplex between socket(s) and stdin - Server

删除回忆录丶 提交于 2020-01-05 07:30:10
问题 I'm writing a client server application and I'm using poll to multiplex between several client sockets and stdin, where I can insert commands (example: stop the server). I believe the structure (the "logic") of my code is correct, however it's not behaving the way I expect it to: struct pollfd pfd[NSERVER]; //defined as 10 pfd[0].fd = fileno(stdin); pfd[0].events = POLLIN; pfd[1].fd = socktfd; //server bind, listen socket pfd[1].events = POLLIN; struct sockaddr_storage remoteaddr; // client

Read from stdin AND forward it to a subprocess in Python

两盒软妹~` 提交于 2020-01-05 05:43:06
问题 I'm writing a wrapper script for a program that optionally accepts input from STDIN. My script needs to process each line of the file, but it also needs to forward STDIN to the program it is wrapping. In minimalist form, this looks something like this: import subprocess import sys for line in sys.stdin: # Do something with each line pass subprocess.call(['cat']) Note that I'm not actually trying to wrap cat , it just serves as an example to demonstrate whether or not STDIN is being forwarded

How can I pass multi-line input (stdin) into a command I'm executing in my Makefile?

℡╲_俬逩灬. 提交于 2020-01-04 04:46:07
问题 I'm writing a dead simple Makefile to be used with GHCi and gedit. Essentially, I define a module to load, and a function (along with its parameters) to call/test. The Makefile would need to execute GHCi and then pass the necessary commands into it. I tried piping with echo , and it worked in a normal shell, but fails due to the way make handles whitespace, strings & formatting. It feeds the whole thing as as one single line, rather than individual lines of input. On top of that, it is a bit

pre-fill stdin in C

心不动则不痛 提交于 2020-01-03 17:40:07
问题 My program is supposed to let the user edit a line of a file. The user edits the line and sends it back by pressing enter. Therefore I would like to print the current line which is about to be edited, but kind of print it on stdin instead of stdout. The only problem I don't know how to solve is how I can prefill the stdin. I've already tried this: char cprefill[] = {"You may edit this line"}; char cbuffer[100]; fprintf(stdin, cprefill); fgets(cbuffer, 100, stdin); This seems to be the

pre-fill stdin in C

喜夏-厌秋 提交于 2020-01-03 17:40:05
问题 My program is supposed to let the user edit a line of a file. The user edits the line and sends it back by pressing enter. Therefore I would like to print the current line which is about to be edited, but kind of print it on stdin instead of stdout. The only problem I don't know how to solve is how I can prefill the stdin. I've already tried this: char cprefill[] = {"You may edit this line"}; char cbuffer[100]; fprintf(stdin, cprefill); fgets(cbuffer, 100, stdin); This seems to be the

Recover stdin from eof in C

牧云@^-^@ 提交于 2020-01-03 17:26:34
问题 I am using the C code below to read user input from a terminal. If the user inputs EOF, e.g. by pressing ^C, stdin is closed and subsequent attempts to read from it, e.g. via getchar() or scanf(), will cause an exception. Is there anything I can do in C to "recover" my program, in the sense that if some user accidently inputs EOF, this will be ignored, so I can read from stdin again? #include <stdio.h> int main(void) { int res_getchar=getchar(); getchar(); return 0; } 回答1: Using ungetc() to

How to read STDIN into a variable in perl

牧云@^-^@ 提交于 2020-01-03 06:33:46
问题 I want to read from STDIN and have everything in a variable, how can I do this? 回答1: This is probably not the most definitive way: my $stdin = join("", <STDIN>); Or you can enable slurp mode and get the whole file in one go: local $/; my $stdin = <STDIN>; [but see man perlvar for caveats about making global changes to special variables] If instead of a scalar you want an array with one element per line: my @stdin = <STDIN>; 回答2: my $var = do { local $/; <> }; This doesn't quite read Stdin, it

Python: Execute scp, stdin for password not working

☆樱花仙子☆ 提交于 2020-01-03 03:34:14
问题 I'm trying the following from subprocess import Popen, PIPE Popen(["scp", "-B","user@url:file", "."], stdin=PIPE, shell=False).communicate(input="password") But I still get the password promt, and no password is sent. I know I can use scp with keys, but this is not what I need. Any help? 回答1: scp interacts with the terminal directly, rather than reading from STDIN , You can't pass the password via a pipe, it security matter for scp and it's the same for sftp, ssh. you can try it in you

Receiving user input after reading piped input

半腔热情 提交于 2020-01-03 03:22:48
问题 I am writing a small, interactive console application in .NET 4. I want to extend this to be able to handle optional redirected input as well, like: echo hello | myapp.exe Trouble is of course that the redirected input steals the "keyboard stream", so any calls to Console.Read*() returns null. What I have at the moment is: // Read piped input try { bool keyAvailable = Console.KeyAvailable; } catch { string redirected = Console.In.ReadToEnd(); // Need to do something here to "un-redirect"

Eclipse reading StdIn(System.in) from console, but will not give any output

为君一笑 提交于 2020-01-03 03:13:13
问题 My problem is that Eclipse's console is taking input in the console, but it never stops taking input and will not give me any output. I created a method called histogram() that takes an integer M and an array a of integers as input. My code to read input and produce output looks like int M = StdIn.readInt(); int[] a = StdIn.readAllInts(); int[] mossah = histogram(M, a); for (int z = 0; z < M; z++) { StdOut.printf("%d", mossah[z]); } I am not allowed to use other libraries, so please do not