stdin

How can I read the output from external commands in real time in Perl?

十年热恋 提交于 2019-12-04 08:04:09
I have a few bash scripts I run, but they can take several hours to finish, during which time they spew out download speeds, ETAs and similar information. I need to capture this information in perl, but I am running into a problem, I cannot read the output line by line(unless I'm missing something). Any help working this out? EDIT: to explain this a little better I'm running several bash scripts along side each other, I wish to use gtk with perl to produce handy progress bars. At present I'm running 2 threads for every bash script I wish to run, one master thread for updating the graphical

ThreadPool of CLI Processes

随声附和 提交于 2019-12-04 07:18:59
I need to pass messages to CLI PHP processes via stdin from Java. I'd like to keep about 20 PHP processes running in a pool, such that when I pass a message to the pool, it sends each message to a separate thread, keeping a queue of messages to be delivered. I'd like these PHP processes to stay alive as long as possible, bringing up a new one if one dies. I looked at doing this with a static thread pool, but it seems more designed for tasks that execute and simply die. How could I do this, with a simple interface to pass a message to the pool? Will I have to implement my own custom "thread

Communicate with subprocess without waiting for the subprocess to terminate on windows

老子叫甜甜 提交于 2019-12-04 07:03:52
I have a simple echoprocess.py: import sys while True: data = sys.stdin.read() sys.stdout.write("Here is the data: " + str(data)) And a parentprocess.py from subprocess import Popen, PIPE proc = Popen(["C:/python27/python.exe", "echoprocess.py"], stdin = PIPE, sdtout = PIPE) proc.stdin.write("hello") print proc.stdout.read() This just hangs until echoprocess.py is terminated. I want to communicate with this subprocess multiple times without having to restart it again. Is this kind of interprocess communication possible with the Python subprocess module on Windows? The main problem is with the

How to redirect data to a “getpass” like password input?

眉间皱痕 提交于 2019-12-04 06:09:24
I'm wring a python script for running some command. Some of those commands require user to input password, I did try to input data in their stdin, but it doesn't work, here is two simple python program represent the problem input.py import getpass print raw_input('text1:') print getpass.getpass('pass1:') print getpass.getpass('pass2:') put_data.py import subprocess import getpass def run(cmd, input=None): stdin=None if input: stdin=subprocess.PIPE p = subprocess.Popen(cmd, shell=True, stdin=stdin) p.communicate(input) if p.returncode: raise Exception('Failed to run command %r' % cmd) input =""

C++: Infinite loop with a simple menu selection

旧时模样 提交于 2019-12-04 05:48:54
问题 The script I am working on is over a page long, so I am going to link it (one simple file): http://pastebin.com/7BVHmQGp I apologize for that. My problem is I get into an infinite loop in my code, for example after I select 1 or 2 for encrypting/unencrypting it lets me enter the word, and when I next enter the "shift" for the cipher it runs an infinite loop of the menu. I had tried for so many hours to debug this, I thought it was a problem with cin , for example when you enter an invalid

Write function result to stdin

早过忘川 提交于 2019-12-04 05:23:20
I'm trying to write the results of a function to stdin. This is the code : def testy(): return 'Testy !' import sys sys.stdin.write(testy()) And the error I get is : Traceback (most recent call last): File "stdin_test2.py", line 7, in <module> sys.stdin.write(testy()) io.UnsupportedOperation: not writable I'm not completely sure, is this the right way of doing things ? You could mock stdin with a file-like object? import sys import StringIO oldstdin = sys.stdin sys.stdin = StringIO.StringIO('asdlkj') print raw_input('.') # .asdlkj stdin is an input stream, not an output stream. You can't write

Using istream_iterator and reading from standard input or file

痴心易碎 提交于 2019-12-04 05:20:38
I'm writing in Microsoft Visual C++ and I'd like my program to either read from standard input or a file using the istream_iterator . Googling the internets hasn't shown how simple I think it must be. So for example, I can write this pretty easily and read from standard input: #include <iostream> #include <string> #include <iterator> using namespace std; int main() { istream_iterator<string> my_it(cin); for (; my_it != istream_iterator<string>(); my_it++) printf("%s\n", (*my_it).c_str()); } Or I can write this and read from a file: #include <iostream> #include <string> #include <iterator>

How do I seek in stdin

女生的网名这么多〃 提交于 2019-12-04 04:34:16
问题 Hello guys I need a help. I want to read from stdin by 16 bytes. Every byte I convert into hexadecimal form. Is there a way I can use read() function to read NOT from the beginning, but for example from the second byte? Also how can I know if I have read the whole stdin ? - This way I could call this function in a cycle until I have read the whole stdin This is a function I made: void getHexLine() { int n = 16; char buffer[n]; read(STDIN_FILENO, buffer, n); buffer[n]='\0'; //printf("%08x", 0)

Python : Postfix stdin

怎甘沉沦 提交于 2019-12-04 04:21:59
I want to make postfix send all emails to a python script that will scan the emails. However, how do I pipe the output from postfix to python ? What is the stdin for Python ? Can you give a code example ? Michael Berkowski To push mail from postfix to a python script, add a line like this to your postfix alias file: # send to emailname@example.com emailname: "|/path/to/script.py" The python email.FeedParser module can construct an object representing a MIME email message from stdin, by doing something like this: # Read from STDIN into array of lines. email_input = sys.stdin.readlines() # email

Scanf returns 0 without waiting for input

被刻印的时光 ゝ 提交于 2019-12-04 04:19:01
问题 I have never programmed in C and today I have to write small code. Program is very easy - I want to add two integers. But when I'm trying to check if given input is a number and first scanf returns 0, the second one returns 0 too without waiting for input. Code: int main() { int a = 0; int b = 0; printf("Number a:\n"); if (scanf("%d", &a) != 1) { printf("Not a number. a=0!\n"); a = 0; } printf("Number b:\n"); if (scanf("%d", &b) != 1) { printf("Not a number. b=0!\n"); b = 0; } printf("%d\n",