stdin

Listening to stdin in Swift

馋奶兔 提交于 2020-02-03 04:44:08
问题 Currently I am trying to listen to user input from the command line in my swift application. I am aware of the readLine() method but it does not really fit my needs. I want to listen for data being inserted on the command line. Like when a user is pressing the ‘up key’ inside the terminal. Something like what can be done in Node.js: stdin.on( 'data', function( key ){ if (key === '\u0003' ) { process.exit(); } // write the key to stdout all normal like process.stdout.write( key ); }); I tried

How can I create an efficient iterator of chars from stdin with Rust?

做~自己de王妃 提交于 2020-02-02 08:11:25
问题 Now that the Read::chars iterator has been officially deprecated, what is the the proper way to obtain an iterator over the chars coming from a Reader like stdin without reading the entire stream into memory? 回答1: The corresponding issue for deprecation nicely sums up the problems with Read::chars and offers suggestions: Code that does not care about processing data incrementally can use Read::read_to_string instead. Code that does care presumably also wants to control its buffering strategy

How can I create an efficient iterator of chars from stdin with Rust?

。_饼干妹妹 提交于 2020-02-02 08:09:13
问题 Now that the Read::chars iterator has been officially deprecated, what is the the proper way to obtain an iterator over the chars coming from a Reader like stdin without reading the entire stream into memory? 回答1: The corresponding issue for deprecation nicely sums up the problems with Read::chars and offers suggestions: Code that does not care about processing data incrementally can use Read::read_to_string instead. Code that does care presumably also wants to control its buffering strategy

How to background a process via proc_open and have access to STDIN?

蓝咒 提交于 2020-01-30 05:41:52
问题 I'm happily using proc_open to pipe data into another PHP process. something like this $spec = array ( 0 => array('pipe', 'r'), // I don't need output pipes ); $cmd = 'php -f another.php >out.log 2>err.log'; $process = proc_open( $cmd, $spec, $pipes ); fwrite( $pipes[0], 'hello world'); fclose( $pipes[0] ); proc_close($process); In the other PHP file I echo STDIN with: echo file_get_contents('php://stdin'); This works fine, but not when I background it. Simply by appending $cmd with & I get

Non-blocking on STDIN in PHP CLI

允我心安 提交于 2020-01-28 04:07:49
问题 Is there anyway to read from STDIN with PHP that is non blocking: I tried this: stream_set_blocking(STDIN, false); echo fread(STDIN, 1); and this: $stdin = fopen('php://stdin', 'r'); stream_set_blocking($stdin, false); echo 'Press enter to force run command...' . PHP_EOL; echo fread($stdin, 1); but it still blocks until fread gets some data. I noticed a few open bug reports about this (7 years old), so if it can't be done, does any one know any crude hacks that could accomplish this (on

Non-blocking on STDIN in PHP CLI

主宰稳场 提交于 2020-01-28 04:07:45
问题 Is there anyway to read from STDIN with PHP that is non blocking: I tried this: stream_set_blocking(STDIN, false); echo fread(STDIN, 1); and this: $stdin = fopen('php://stdin', 'r'); stream_set_blocking($stdin, false); echo 'Press enter to force run command...' . PHP_EOL; echo fread($stdin, 1); but it still blocks until fread gets some data. I noticed a few open bug reports about this (7 years old), so if it can't be done, does any one know any crude hacks that could accomplish this (on

unbuffered read from stdin in python

[亡魂溺海] 提交于 2020-01-24 02:34:07
问题 I'm writing a python script that can read input through a pipe from another command like so batch_job | myparser My script myparser processes the output of batch_job and write to its own stdout. My problem is that I want to see the output immediately (the output of batch_job is processed line-by-line) but there appears to be this notorious stdin buffering (allegedly 4KB, I haven't verified) which delays everything. The problem has been discussed already here here and here. I tried the

How to properly flush stdin in fgets loop

送分小仙女□ 提交于 2020-01-21 12:52:00
问题 I have found the example of clearing stdin using while((c = getchar()) != '\n' && c != EOF) on here a few times, and tried to use it in a loop that gets input via fgets. I need to flush, since the loop takes the \n character from the last input and runs with it again. So what happens is that I have to press enter twice now. Why is this happening, and how can I fix this? #define BUFFER_LIMIT 50 do { int c; while ((c = getchar()) != '\n' && c != EOF); printf("console> "); fgets(input_buffer,

How to properly flush stdin in fgets loop

余生长醉 提交于 2020-01-21 12:51:12
问题 I have found the example of clearing stdin using while((c = getchar()) != '\n' && c != EOF) on here a few times, and tried to use it in a loop that gets input via fgets. I need to flush, since the loop takes the \n character from the last input and runs with it again. So what happens is that I have to press enter twice now. Why is this happening, and how can I fix this? #define BUFFER_LIMIT 50 do { int c; while ((c = getchar()) != '\n' && c != EOF); printf("console> "); fgets(input_buffer,

Read a File from redirected stdin with python

痞子三分冷 提交于 2020-01-21 07:29:08
问题 I am trying to read the content of a text file that was redirected stdin via the command line, and send it by the Internet when the receiver has to assemble it back to it's original form. For instance: $ python test.py < file.txt I have tried to read the file and to assemble it back with the following code inspired by link: for line in sys.stdin: stripped = line.strip() if not stripped: break result = result + stripped print "File is beeing copied" file = open("testResult.txt", "w") file