stdin

Node.js port listening and reading from stdin at the same time

只谈情不闲聊 提交于 2019-12-06 07:11:43
I have a socket server in Node.js and I'd like to be able to read from stdin at the same time the server is listening. It works only partially. I'm using this code: process.stdin.on('data', function(chunk) { for(var i = 0; i < streams.length; i++) { // code that sends the data of stdin to all clients } }); // ... // (Listening code which responds to messages from clients) When I don't type anything, the server responds to messages of the clients, but when I start typing something, it isn't until I press Enter that it continues with this task. In the time between starting to type something and

How to avoid going to new line with stdin in Rust

巧了我就是萌 提交于 2019-12-06 06:34:38
I have this code: fn main() { let mut stdin = io::stdin(); let input = &mut String::new(); loop { input.clear(); print!("Your age: "); stdin.read_line(input); print!("{}", input); } } So when I input something, the programs returns "Your age:" plus my input. But when I run the program I don't want to write the input in a new line. To do something like that in Python, I can write: var = input("Your age: ") How can I avoid going to a new line? I'm sure it's simple but I really can't realize how to do that, I tried a lot of different stuff... antoyo You need to flush stdout before reading the

Stopping getline in C

夙愿已清 提交于 2019-12-06 06:06:47
Here I'm trying to get an user input with getline . Upon receiving an interrupt ^C I want it to signal getline to stop and resume with my program instead of terminating it. I tried to write a newline to stdin but apparently that doesn't work. fwrite("\n", 1, 1, stdin); So what would be a way to achieve this? Assuming your code resembles this: int main(int argc, char **argv) { //Code here (point A) getline(lineptr, size, fpt); //More code here (point B) } Include <signal.h> and bind SIGINT to a handler function f . #include <signal.h> //Declare handler for signals void signal_handler(int signum

How to process stdin to stdout in php?

天涯浪子 提交于 2019-12-06 04:13:00
问题 I'm trying to write a simple php script to take in data from stdin , process it, then write it to stdout . I know that PHP is probably not the best language for this kind of thing, but there is existing functionality that I need. I've tried <?php $file = file_get_contents("php://stdin", "r"); echo $file; ?> but it doesn't work. I'm invoking it like this: echo -e "\ndata\n" | php script.php | cat . and get no error messages. The script I'm trying to build will actually be part of a larger

ThreadPool of CLI Processes

时间秒杀一切 提交于 2019-12-06 03:53:51
问题 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,

python 3 subprocess error in bytes

懵懂的女人 提交于 2019-12-06 03:29:30
问题 Very good, I have a little problem with the output of the thread, I get in unicode or I think and not let me convert it to utf-8, this is the code: import subprocess,sys,time string = b'dir' process = subprocess.Popen('cmd.exe', shell=True,cwd="C:\\",stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=None) process.stdin.write(string) o,e=process.communicate() process.wait() process.stdin.close() print (o.encode('utf-8')) I jump the following error: **Traceback (most recent call last): File

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

人走茶凉 提交于 2019-12-06 03:26:34
问题 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

Passing 2 stdin arguments to a ImageMagick child_process

ぐ巨炮叔叔 提交于 2019-12-06 03:19:55
I have certain limitations that I won't specify that require me to use ImageMagick as a child-process. I have multiple base 64 strings of jpg files which I want ImageMagick to process. Specifically I want ImageMagick to join the jpg files together. If I had 2 regular jpg files then from the command line I would use the following format. node convert in_1.jpg in_2.jpg +append out.jpg in a js file I would use var spawn, magicCommands, imagic; spawn = require('child_process').spawn; magicCommands = ["in_1.jpg", "in_2.jpg", "+append", "out.jpg"]; imagic = spawn("convert", magicCommands); Now if I

Using istream_iterator and reading from standard input or file

元气小坏坏 提交于 2019-12-06 02:46:10
问题 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()); }

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

瘦欲@ 提交于 2019-12-06 02:15:26
问题 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