FAQ Database Discussion Community


python sys.stdin.read() unwanted split

python,linux,stdin,geoip
i'm trying to make a script that i can pipe IP addresses to and have it return the geoip location. When I try this, it looks like its splitting each IP address by 1 character at a time and failing when trying to run iplookup() #!/usr/bin/env python import sys from...

Using raw_input causes problems with PyQt page loading

python,pyqt4,stdin,raw-input,qwebpage
I'm using PyQt4 to enter credentials into a domain login page and pull data from several additional pages in the domain. Everything works exactly as expected when supplying login or search credentials from within the code. When I open up raw_input to allow the user to enter information, it causes...

Python subprocess input is read twice

python,io,subprocess,stdin
I need to wrap a program in python and feed it input and print output. But if it give it one line of input it seems to use this as input until the program terminates. I've written a very basic program in C (called inout) which takes in two lines...

Extract patterns of STDIN with Java 8 Stream API

java,regex,inputstream,java-8,stdin
I am trying to parse STDIN and extract every string that matches with a specific pattern (for example email pattern). Also the program has to count the number of occurences of each match. When it finishes the sum, it will print the list of matches sorted alphabetically. I thought that...

How to stop reading input from user after a certain char using raw_input() in Python?

python,stdin
If I use raw_input() it takes all the user input. I want to stop taking input just when user enters '-1'. What I mean is if user enters '12 22 -23 3 -1 23 -1 23', it should not read after 3. Any other way of reading input will also...

Take file as an input from the command line c++

c++,file-io,stdin
Currently I have code that uses cin to get the name of the file to be used as input when the program is executed. I would like to have it so that when i run the program i can add the file redirection and the filename and run it as...

Separate STDIN between parent and child process

perl,unix,io,stdin
Redirect two or more STDOUT to a single STDIN http://en.wikipedia.org/wiki/Standard_streams says "More generally, a child process will inherit the standard streams of its parent process." I am assuming if a child process close stdin then parent's stdin gets closed as well and not gettin any user input for code such...

How to continue reading from stdin after Control-D on OS/X

osx,stdin,eof
I would like to use EOF to terminate reading bulk user input, but continue to be able to accept user CLI input. It seems that Linux allows this behaviour, but OS/X simply shuts down the stdin input steam (as seem from the following test program). Is there any workaround to...

How can I check if user input is a directory path in php command line

php,cmd,stdin
I am using php to write a small cmd program, I want to check if user input in php command line is valid directory path or not in order to apply my functions on that directory . This is a piece of code I write: $stdin = fopen('php://stdin', 'r'); do{...

End of File in stdin

c,stdin,eof
A question about this has been asked here End of File (EOF) in C but it still doesn't completely solve my problem. EOF makes sense to me in any datastream which is not stdin, for example if I have some data.txt, fgetc() will read all the chars and come to...

Grep-ing non-seekable file

linux,bash,grep,stdin
How does grep allocate buffer for reading lines when non-seekable files like devices, sockets, pipes or fifos are used? I tried doing the following grep hello - I gave as input a single line containing around 9484 characters including space. Grep processed some characters (I guess around 4K) and just...

Read all text from stdin

node.js,stdin,synchronous
I'm writing a program in Node.js that (in some situations) wants to act as a simple filter: read everything from stdin (up to end of file), do some processing, write the result to stdout. How do you do the 'read everything from stdin' part? The closest solutions I've found so...

Continue reading on sys.stdin

python,stdin,sys
Is it possible to continue reading input on sys.stdin? I'm trying to continuously execute a function based on input. (My function only prints to sys.stdout and sys.stderr, and doesn't return anything.) My Code: def prime(number): number = abs(int(number)) for i in range(3, number): if number % i == 0: print("Not...

writing to stdin from java to python

java,python,stdin
I am having an issue trying to write to stdin from java. here is my python code which would be receiving the stdin input import sys data = sys.stdin.readlines() print data I am trying to write out to stdout in java but it keeps on printing to console. BufferedWriter out...

getc() for passed in input and file reading in C

c,arrays,input,stdin,getc
I have to develop a program in C that can have two kinds of inputs. By feeding it a string ( I am assuming like this filename < String1234455678, please correct me if I am wrong). By reading data from some file(s). I have to do some checks regarding the...

passing variables from bash to executable (which reads argument with stdin)

bash,variables,executable,stdin
I have the following test.cpp c++ program #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; int main() { float a,b,c; cout<<"Give 1st number"; cin>>a; cout<<"Give 2nd number:"; cin>>b; c=a+b; cout<<"\n"<<a<<"+"<<b<<"="<<c<<endl; return 0; } and I want to create a shell script which gives the input variables. I know how...

python how to kill a popen process, shell false [why not working with standard methods] [SOLVED]

python,stdin,popen,kill,omxplayer
I'm trying to kill a subprocess started with: playing_long = Popen(["omxplayer", "/music.mp3"], stdout=subprocess.PIPE) and after a while pid = playing_long.pid playing_long.terminate() os.kill(pid,0) playing_long.kill() Which doesn't work. Neither the solution pointed out here How to terminate a python subprocess launched with shell=True Noting that I am using threads, and it is...

subroutine not reading from stdin

linux,assembly,x86,stdin
code is as follows getstr: ; get a LF terminated string from stdin ; in: EAX = dest buffer ; out: ax = bytes read ; EAX NOT preserved, all other registers preserved ;op mod opr1 opr2 comment ;-------------------------------------------------------- push ebx push ecx push edx sub esp, 2 ; allocate...

perl subroutine from reading STDIN (“Press enter to reset”) only works the first time

perl,stdin,subroutine
I have made a little perl program for a kids demonstration and I'm trying to keep the screen clean and simple with a clear subroutine, but it's only working the first time, and then will not respond to input, only clearing the screen, and I can't work out why. I'm...

2- vs 3-argument open with '-'

perl,io,stdin
The following opens STDIN and then echos user input: open my $in, '-'; print "You said: $_" while(<$in>); However, the following snippet dies because it can't find any file called '-': open my $in, '<', '-'; # dies print "You said: $_" while(<$in>); Why does the two-argument open work for...

C / C++ Putting a string into a two dimensional array?

c++,c,arrays,string,stdin
Hey very new to c/c++ and was hoping I could get pushed in the right direction on fixing my errors. I am creating a program that opens a file and reads the text in the file and puts it into a string. From there I create a two dimensional array...

Gem to capture/replay stdin input in ruby

ruby,stdin
Is there a ruby gem that automatically logs input from $stdin, while preserving normal execution flow for the program? I was thinking something like: def gets_with_logging input = gets_without_logging File.write('/path/to/file', input) return input end alias_method_chain :gets, :logging Then you could use that file later on to replay the same input....

Multiple file input, with stdin // Argparse4j, Java

java,file,command-line-interface,command-line-arguments,stdin
I'm trying to use Argparse4j to build a command line utility. I need to create an option that accepts multiple input files, but also accepts stdin: subparser.addArgument("input") .nargs("*") .setDefault(Arrays.asList("-")) .type(Arguments.fileType().acceptSystemIn().verifyCanRead()); If I don't use Arrays.asList, then sometimes I get just a File object, instead of a List<File>. However, using nargs("*")...

Read input into a dynamic sized int?

c,pointers,int,stdin
I need to read a huge number from the stdin, here is the code i have so far: int main() { int x; int* n1 scanf("%d", &x); // I get the number of digits the integer will have n1 = malloc(x * sizeof(int)); // I resize the integer pointer }...

Difference between fflush(stdin) and flushstdin()

c,stdin,fflush
What is the difference between using fflush(stdin) and flushstdin()? The only difference I know is that I need to write that void stuff before using flushstdin(), but I don't know why. void flushstdin() { int c; while((c = getchar()) != '\n' && c != EOF); } int main () {...

How to know when stdin is empty if it contains EOF?

python,stdin,cat
In an attempt to create a simple cat clone in python, sys.stdout.write(sys.stdin.read()) I noticed that this fails horribly for binary files (i.e. python cat.py < binaryfile > supposed_copy) containing the CTRL+Z EOF / substitude character 0x1a, since that seems to cause read() to consider its work done. I cannot simply...

Writing end-of-transmission to stdin of a running process

c,bash,stdin
I have a multi-threaded process that waits for input from stdin to shut down cleanly: //launch worker threads fgetc(stdin); run = 0; //let threads shut down cleanly From the terminal that I launched the process from, I can simply hit ENTER and the process will end. However, if I try...

How to compare input from process.stdin to string in NodeJS?

node.js,stdin
I'm using nodeJS and I want to be able to pass it commands via stdin. To do this I'm using process.stdin. Ideally I'd have a giant switch with various command strings like "load" or "stop", but I can't get the comparison to work. I've tried slicing out newlines, converting to...

Python multiple read on stdin cause it to block

python,stdin
I am a student in programming school and need to complete a project playing with financial stock's data. I chose to do it in Python as it's the only language I played few days with which is not taught in my school, I must be able to read on the...

linux stdin, stdout pipe

linux,pipe,stdout,stdin
I have a brick.sprite. I have a executable in Debain 8 "Kali Linux" with this code: #include <stdio.h> #include <stdint.h> #include <iostream> /** * To use this file, pipe a sprite of the old format into stdin, and * redirect stdout to a second file of your chosing. The sprite...

How is perl -i *really* implemented?

perl,stdin
In the description of the Perl -i[extension] feature at http://perldoc.perl.org/perlrun.html, code that is materially identical to the following program is given as "an equivalent" to using perl -pi.orig ...: #!/usr/bin/perl use strict; use warnings; my $extension = '.orig'; my $oldargv = ''; my $backup; LINE: while (<>) { if ($ARGV...

Problems with taking input from stdin - Invalid read/write from valgrind

c,io,stdin,fgets,fscanf
I ran valgrind on a program I'm working on and I'm getting the following errors - I can't figure out why. Any help would be greatly appreciated ahead of time. Let me know if you need any more information ==27928== Invalid read of size 1 ==27928== at 0x4EB9390: __GI___rawmemchr (rawmemchr.S:25)...

import scala.io.StdIn

eclipse,scala,stdin,scala-ide
I'm using Eclipse ScalaIDE and for some reason I'm not able to import scala.io.StdIn I'm getting a red squiggly that tells me: object StdIn is not a member of package io And I'm seeing that it's not in that scala.io jar file. The ScalaDoc, however says it should be there....

How can I get user input without receiving an “Unsed Variable” warning?

input,rust,stdin
I'm taking a look at Rust and decided to build a small program that takes a user's input and prints it, but also want to do some math stuff with it for practice. Currently, this is how I am taking user input: let mut number = String::new(); let input =...

C stdin limitation is blocking me from reading a line with over 1200 characters

c,stdin,fgets
I have this simple program: #include <stdio.h> #include <stdlib.h> #include <string.h> size_t strlen(const char *str) { const char *s; for (s = str; *s; ++s); return(s - str); } /* * Initial size of the read buffer */ #define DEFAULT_BUFFER 1024 /* * Standard boolean type definition */ typedef enum...

PYTHON subprocess cmd.exe closes after first command

python,cmd,subprocess,stdout,stdin
I am working on a python program which implements the cmd window. I am using subproccess with PIPE. If for example i write "dir" (by stdout), I use communicate() in order to get the response from the cmd and it does work. The problem is that in a while True...

one stdout to one stdin from java to python

java,python,stdout,stdin
I am having this java code public static main void (String[] args) { System.out.println("this is iteration 1"); System.out.println("this is iteration 2"); System.out.println("this is iteration 3"); System.out.println("this is iteration 4"); } Python import sys try: while True: data = raw_input() print "in python " + data except: print error Desired output...

Windows/Linux child process STDIN differences

linux,windows,perl,process,stdin
I built a simple text processing script at work to be used by another program. When I was done, someone remembered that the script needs to not block STDIN/STDOUT for the tool using it to work right, and modified the script accordingly. The script opens *nix's cat in a subprocess...

stdin Java Input

java,stdin,bufferedreader
I am having problems with STDIN I would to read the following 2 string, for example: Input: abc xyz When typing "abc", then press Enter, I get abc back. However i dont want that. I would like to type another string just like input above. So what want is: Type...

python - is it possible to enter user-chosen input and output files

python,user-input,stdin
I'm a newbie in python, so please bear with me. I don't know how to describe,so I'll just show an example. python CODE.py -i1 input1.txt -i2 input2.txt -o output.txt Is such thing possible with python? I've looked up for a while but haven't find an answer. Thank you!...

Can I use STDIN for IPC?

c,gcc,ipc,stdin
Can I use standard input for interprocess communication? I wrote the following gnu c code as an experiment, but the program hangs waiting for input after printing the character defined as val. Neither a newline nor fflush in the sending process seem to alleviate the problem. #include <unistd.h> #include <stdio.h>...

Python interactive after reading sys.stdin

python,parsing,stdin,python-interactive
I'm trying to write a small graph parser that reads from stdin and writes the processed output to stdout along the lines of: # parser.py G = defaultdict(list) for line in sys.stdin: node, neighbor = line.split() G[node].append(neighbor) print(G) I would like to invoke the script with python -i parser.py <...

how to read a text file in c and then split each line into tokens?

c,string,pointers,stdin
The input text file has some numbers per line, numbers are split by space. The first two lines only got one number, and the following lines got three. What I want to do is read each line of the input and store these numbers. This is what I've got so...

Reading in filenames from stdin c

c,stdin,fgets,strtok,stat
While this is a very basic problem that should be easy to solve, I haven't been able to figure it out. I am attempting to read in a string containing filenames broken up by whitespaces from stdin. While it appears to read all the filenames correctly, when I use stat()...