stdin

Collect data in chunks from stdin: Python

十年热恋 提交于 2019-12-13 09:07:20
问题 I have the following Python code where I collect data from standard input into a list and run syntaxnet on it. The data is in the form of json objects from which I will extract the text field and feed it to syntaxnet. data = [] for line in sys.stdin: data.append(line) run_syntaxnet(data) ##This is a function## I am doing this because I do not want Syntaxnet to run for every single tweet since it will take a very long time and hence decrease performance. Also, when I run this code on very

writing to stdin, access denied

早过忘川 提交于 2019-12-13 07:35:20
问题 I'm trying to write a python script that starts a subprocess, and writes to the subprocess stdin. Does some tests on teh output and then writes more commands to stdin. I have tried: def get_band(): print "band" p = subprocess.Popen(["/path/to/program","-c","-"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) ran_stdout = p.communicate(input='show status')[0] print(ran_stdout) However the print statement gives: Unable to connect at 127.0.0.1, Connection refused. I was

How can I capture data coming into my Android app from the standard input (stdin)?

不打扰是莪最后的温柔 提交于 2019-12-13 07:06:08
问题 I am writing an app that uses an external USB barcode/RFID scanner. The scanner is a standard HID, and works well on my Android devices. I plug it in, hit the scan button, and data pops up in a text editing app. The same can be said for a standard USB keyboard. I plug it in, start typing, and data shows up in a text editing app. Here is where I need assistance. What I need to do is manipulate the data coming into my app, from the scanner or external keyboard, before I can place it into the

How can I pass STDin to IRB without it exiting after processing this input?

依然范特西╮ 提交于 2019-12-13 06:06:36
问题 I'm using a short bash script to help me test an implementation of linked lists in ruby for class. I know about rspec and unit testing, and I'm certain they're better options for what I'm trying to do, but I was able to figure out this command echo "require './nodes'" | irb The output afterwards is Switch to inspect mode. require './nodes' true Technically a success, but the irb process ends there. So I tried echo "require './nodes'" | irb --noinspect Which gave me Switch to non inspect mode.

Pass stdout of child to parents stdin

孤者浪人 提交于 2019-12-13 04:54:44
问题 I try to pass the stdout of an program in a child process to the stdin in the parents process. In bash this would look like this: wget "adress"|less My code looks like this: int fd[2]; pid_t child_id; int status; char *args[] = {"wget","-O -",argv[1], NULL}; int pipe(int fd[2]); child_id = fork(); if (child_id == -1) { printf ("Fork error\n"); } if (child_id == 0) { close(fd[0]); int c = dup2(fd[1],1); execl ("/usr/bin/wget", "wget", "-qO-",argv[1], NULL); } else{ waitpid(child_id,&status,0);

C: Clearing STDIN

时光怂恿深爱的人放手 提交于 2019-12-13 04:46:07
问题 basically in codeblocks for windows before each printf I have "fflush(stdin);" which works. When I copied my code to Linux, it doesn't work, nor does any of the alternatives for "fflush(stdin);" that I've found. No matter which way I seem to do it, the input doesn't seem to be clearing in the buffer or something in my code is incorrect. #include <stdio.h> #include <math.h> #include <limits.h> #include <ctype.h> int main() { char pbuffer[10], qbuffer[10], kbuffer[10]; int p=0, q=0, k=0; int r,

Reversing stdin in C

强颜欢笑 提交于 2019-12-13 04:36:52
问题 I need some advice on how to reverse the contents of stdin. This is the part of my code which handles reversing stdin: int reversestdin(FILE *file) { int a, b; int lineas=0; while ((a=fgetc(stdin)) !=EOF) { if (a=='\n') lineas++; } for(b=0; b<lineas; b++) { rewind(stdin); int d,len, e; char str[2048], *ptr; for(e=0; e<=b; e++) { fgets(str, 2048, stdin); } ptr=str; for(d=0; d<2048; d++) { if(*ptr=='\n') break; if(*ptr=='\0') break; ptr++; } len=d; ptr--; for(d=len; d>0; d--) { printf("%c",

How do I interact with a console app as if I'm a user typing things into it?

▼魔方 西西 提交于 2019-12-13 04:20:59
问题 I'm trying to write a Python program that interacts with the bsdgames trek program. It's kind of like Zork with Klingons: * * * S T A R T R E K * * * Press return to continue. What length game: short What skill game: fair Enter a password: hunter2 10 Klingons 2 starbases at 3,6, 0,2 It takes 400 units to kill a Klingon Command: I'm currently trying to use subprocess.Popen() to interact with it: >>> import subprocess >>> t = subprocess.Popen('trek', stdin=subprocess.PIPE, stdout=subprocess

Pipe to my program as a log rotator

依然范特西╮ 提交于 2019-12-13 01:18:35
问题 I'm trying to implement my own log rotator (create new log file whenever filesize reaches 10 MB). The part that reads the standard input and writes it to the file is this: fstream file("log.txt", ios::out | ios::app); while (std::cin >> lineInput) { file << lineInput; } But the problem is that piped data gets ruined. Tabs and new lines are always lost. So for example if my program's name is LogRotator , then the command: ls | ./LogRotator Just concatenates all the file names together, like

Question about while(!EOF)

三世轮回 提交于 2019-12-13 01:14:36
问题 Im reading in values from stdin and I want to keep reading the file until I have completed reading it all the way, so I am using while(!EOF){ scanf(...) } However, the code fragment doesn't seem to do anything, while(!EOF){ scanf("%d %d %d %d", &imageWidth, &imageHeight, &safeRegionStart, &safeRegionWidth); printf("---imageWidth=%d imageHeight=%d safeRegionStart=%d safeRegionWidth=%d---\n", imageWidth, imageHeight, safeRegionStart, safeRegionWidth); totalP = imageWidth * imageHeight ;