stdin

How can I split and re-join STDOUT from multiple processes?

夙愿已清 提交于 2019-12-04 20:35:34
问题 I am working on a pipeline that has a few branch points that subsequently merge-- they look something like this: command2 / \ command1 command4 \ / command3 Each command writes to STDOUT and accepts input via STDIN. STDOUT from command1 needs to be passed to both command2 and command3, which are run sequentially , and their output needs to be effectively concatenated and passed to command4. I initially thought that something like this would work: $ command1 | (command2; command3) | command4

Cross-platform (linux/Win32) nonblocking C++ IO on stdin/stdout/stderr

我的未来我决定 提交于 2019-12-04 20:28:57
问题 I'm trying to find the best solution for nonblocking IO via stdin/stdout with the following characteristics: As long as there is enough data, read in n -sized chunks. If there's not enough data, read in a partial chunk. If there is no data available, block until there is some (even though it may be smaller than n ). The goal is to allow efficient transfer for large datasets while processing 'control' codes immediately (instead of having them linger in some partially-filled buffer somewhere).

How to read stdin when no arguments are passed?

纵然是瞬间 提交于 2019-12-04 18:01:36
问题 Script doesn't work when I want to use standard input when there are no arguments (files) passed. Is there any way how to use stdin instead of a file in this code? I tried this: if [ ! -n $1 ] # check if argument exists then $1=$(</dev/stdin) # if not use stdin as an argument fi var="$1" while read line do ... # find the longest line done <"$var" 回答1: Just substitute bash's specially interpreted /dev/stdin as the filename: VAR=$1 while read blah; do ... done < "${VAR:-/dev/stdin}" (Note that

Cannot trigger 'end' event using CTRL D when reading from stdin

随声附和 提交于 2019-12-04 17:57:33
问题 In the following code process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { process.stdout.write('data: ' + chunk); }); process.stdin.on('end', function() { process.stdout.write('end'); }); i can't trigger the 'end' event using ctrl+D, and ctrl+C just exit without triggering it. hello data: hello data data: data foo data: foo ^F data: ♠ ^N data: ♫ ^D data: ♦ ^D^D data: ♦♦ 回答1: I'd change this: process.stdin.on('end', function() { process.stdout

Perl with Sublime Text 2: <STDIN> not working

一个人想着一个人 提交于 2019-12-04 17:36:52
I'm new to Perl and am trying to write a simple program that prompts the user to enter a number. I then want that number to be printed. I think I have the correct code, but when I run the program I'm not able to enter anything. I'm using Sublime Text 2. Am I missing a plugin or something? How do I get this to work? I've only done simple if/else statements prior to this and everything worked. I just can't seem to prompt the user for input. Here is the code: print ("Please enter a number: \n"); $seq = <STDIN>; print("Sequence = $seq \n"); And here is the output: Use of uninitialized value $seq

Custom standard input for python subprocess

ε祈祈猫儿з 提交于 2019-12-04 16:49:46
I'm running an SSH process like this: sshproc = subprocess.Popen([command], shell=True) exit = os.waitpid(sshproc.pid, 0)[1] This works and opens an interactive terminal. Based on the documentation for subprocess , sshproc is using the script's sys.stdin . The question is: how can I print to stderr or a file what input is being received to this child process? I am creating a logging API, and currently lose the ability to record what commands are run over this SSH session. I don't need the answer, just a nudge in the right direction. Thanks everyone! EDIT: It is important that I start the

Reading long int using scanf

喜欢而已 提交于 2019-12-04 16:28:18
问题 To read an int using scanf we use: scanf("%d", &i); What if i is a long not int ?? Note: when using %d with long it gives me an irritating warning.. 回答1: Just use long l; scanf("%ld", &l); it gives me an irritating warning.. That warning is quite right. This is begging for stack corruption. 回答2: For gods sake: long n; scanf( "%ld", & n ); 回答3: scanf("%ld", &i); You can also use "%Ld" for a long long (and depending on your compiler, sometimes also "%lld" ). Take a look at the Conversions

sys.stdin.readline() reads without prompt, returning 'nothing in between'

给你一囗甜甜゛ 提交于 2019-12-04 16:22:45
问题 I have a function that executes the following (among other things): userinput = stdin.readline() betAmount = int(userinput) Is supposed to take input integer from stdin as a string and convert it to an integer. When I call the function, however, it returns a single newline character (it doesn't even wait for me to input anything). Earlier in the program I get some input in the form of: stdin.read(1) to capture a single character. Could this have something to do with it? Am I somehow writing a

How to implement a stdin, stdout wrapper?

拥有回忆 提交于 2019-12-04 14:13:09
问题 I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly. How to implement this ? X and Y can be hardcoded. Bash? Python? Edit: I can't run the program twice. It has to be one instance. Here is the pseudocode: def wrap(cmd, in, expected_out): p = exec(cmd) p.writeToStdin(in) out = p.readBytes

How do I push a string to stdin? Provide input via stdin on startup, then read stdin input interactively

谁说胖子不能爱 提交于 2019-12-04 13:36:21
Is there a way to "push" a string to the stdin stream of a program when calling it? So that we would have the effect of echo "something" | ./my_program but instead of reading EOF after "something" , my_program would read its further input from the original stdin (e.g., the keyboard). Example: Say we want to start a bash shell, but the first thing we would like to do inside it is to call date . echo date | bash would not do the job, as the shell would terminate after running date . Jonathan Leffler This might work: (echo "something"; cat -) | ./my_program It creates a sub-shell where the first