stdin

Check if stdin is empty

假装没事ソ 提交于 2020-01-14 07:43:18
问题 I searched but did not get a relevant answer to this question, i am working on a linux machine, i wanted to check if the standard input stream contains any character, without removing the characters from the stream. 回答1: You might want to try select() function, and wait for having data into the input stream. Description: select() and pselect() allow a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operation

How can I check if a CLI program is waiting for input from stdin?

a 夏天 提交于 2020-01-13 16:48:07
问题 How can I check if a CLI program, that I just started with CreateProcess(), is waiting for input from stdin with the Windows C API? 回答1: as some of the comments above have said, you cannot check if your program is waiting for stdin once it has already started waiting. You could use an event handler or you could simply have a read from stdin with a timeout, where on occurrence of the timeout you flag that you are waiting for input and start waiting with a timeout again. 来源: https:/

How can I check if a CLI program is waiting for input from stdin?

北城以北 提交于 2020-01-13 16:48:06
问题 How can I check if a CLI program, that I just started with CreateProcess(), is waiting for input from stdin with the Windows C API? 回答1: as some of the comments above have said, you cannot check if your program is waiting for stdin once it has already started waiting. You could use an event handler or you could simply have a read from stdin with a timeout, where on occurrence of the timeout you flag that you are waiting for input and start waiting with a timeout again. 来源: https:/

In python, how to check the end of standard input streams (sys.stdin) and do something special on that

孤街醉人 提交于 2020-01-12 07:07:13
问题 I want to do something like: for line in sys.stdin: do_something() if is **END OF StdIn**: do_something_special() After a few tries, for now I am doing this: while True: try: line = sys.stdin.next() print line, except StopIteration: print 'EOF!' break Or with this: while True: line = sys.stdin.readline() if not line: print 'EOF!' break print line, I think both above ways are very similar. I want to know is there a more elegant (pythonic) way to do this? Early failed tries: I first tried to

In python, how to check the end of standard input streams (sys.stdin) and do something special on that

北城余情 提交于 2020-01-12 07:06:33
问题 I want to do something like: for line in sys.stdin: do_something() if is **END OF StdIn**: do_something_special() After a few tries, for now I am doing this: while True: try: line = sys.stdin.next() print line, except StopIteration: print 'EOF!' break Or with this: while True: line = sys.stdin.readline() if not line: print 'EOF!' break print line, I think both above ways are very similar. I want to know is there a more elegant (pythonic) way to do this? Early failed tries: I first tried to

How can I read piped input in Perl on Windows?

微笑、不失礼 提交于 2020-01-11 18:52:29
问题 I am trying to create something in Perl that is basically like the Unix tee command. I'm trying to read each line of STDIN , run a substitution on it, and print it. (And eventually, also print it to a file.) This works if I'm using console input, but if I try to pipe input to the command it doesn't do anything. Here's a simple example: print "about to loop\n"; while(<STDIN>) { s/2010/2009/; print; } print "done!\n"; I try to pipe the dir command to it like this: C:\perltest>dir | mytee.pl

Compress files while reading data from STDIN

拜拜、爱过 提交于 2020-01-11 15:04:09
问题 Is it possible to compress (create a compressed archive) data while reading from stdin on Linux? 回答1: Yes, use gzip for this. The best way is to read data as input and redirect the compressed to output file i.e. cat test.csv | gzip > test.csv.gz cat test.csv will send the data as stdout and using pipe-sign gzip will read that data as stdin. Make sure to redirect the gzip output to some file as compressed data will not be written to the terminal. 回答2: Yes, gzip will let you do this. If you

C - getchar() in a loop?

给你一囗甜甜゛ 提交于 2020-01-11 12:49:08
问题 How I can use getchar() in a loop? Now I have... for (p=0; p<n_players; p++) { ... fflush(stdin); getchar(); } But it doesn't work... if n_players is 3, it execute getchar 2 times only at the end... for (p=0; p<n_players; p++) { blank_start(); ascii_art_title(); printf("%s, tocca a te...\n",player_info[p].player_name); srand(time(NULL)); random_speed = MIN_WHEEL_SPEED + rand()%MAX_WHEEL_SPEED; move_wheel_pointer(random_speed, &pointer); if (player_points(&wheel[pointer]) == 0){ player_info[p]

redirect a file contents to standard input in php

我们两清 提交于 2020-01-11 10:11:57
问题 I have a file abc.txt with contents like: hello hi good bad ... .... Now, How to redirect the contents of the file line by line to a php script's standard input , so that when the php script is executed, it can collect the inputs by any of these commands: $f = fopen('php://stdin', 'r'); $line = fgets($f); or $f = fgets(STDIN); 回答1: php yourscript.php < yourinputfile should do the trick. 来源: https://stackoverflow.com/questions/6321198/redirect-a-file-contents-to-standard-input-in-php

PHP Pipe into a background process

雨燕双飞 提交于 2020-01-11 07:31:11
问题 I'm trying to use popen to run a php script in the background. However, I need to pass a (fairly large) serialized object. $cmd = "php background_test.php >log/output.log &"; $fh = popen($cmd, 'w'); fwrite($fh, $data); fclose($fh); //pclose($fh); Without the ampersand this code executes fine but the parent script will wait until the child is finished running. With the ampersand STDIN gets no data. Any ideas? 回答1: As far as I know there is no way in php to send a process in background and