stdin

How do I chain stdout in one child process to stdin in another child in C?

蹲街弑〆低调 提交于 2019-11-29 05:09:23
I've been messing around in C trying to figure out how to do this. Let's say I have my main program, the parent process. The parent creates three child processes, each of which will eventually run programs (but that's not important right now). What I'd like to do is make it so that the first child's stdout will be received by the second child's stdin. The second child's stdout will then be received by the third child's stdin. The parent process's stdin/stdout aren't messed with at all. So far, what I've got is pipe(procpipe); parentPid = getpid(); for(i = 0; i < 3; i++) { if(getpid() ==

sys.stdin.readlines() hangs Python script

江枫思渺然 提交于 2019-11-29 03:51:56
Everytime I'm executing my Python script, it appears to hang on this line: lines = sys.stdin.readlines() What should I do to fix/avoid this? EDIT Here's what I'm doing with lines : lines = sys.stdin.readlines() updates = [line.split() for line in lines] EDIT 2 I'm running this script from a git hook so is there anyway around the EOF? This depends a lot on what you are trying to accomplish. You might be able do: for line in sys.stdin: #do something with line Of course, with this idiom as well as the readlines() method you are using, you need to somehow send the EOF character to your script so

Write to spawned process stdin nodejs?

我是研究僧i 提交于 2019-11-29 02:35:10
问题 I have a script that I want to run from another one. The problem is that the child script (process) needs an user input before it continues. var child = spawn('script'); child.stdin.setEncoding('utf8'); child.stdout.on('data', function (data) { console.log(data.toString().trim()); // tells me to input my data child.stdin.write('my data\n'); }); After I input my data the child script should continue but instead it hang in there. Solution Actually the above code work for me. I'm using commander

Using Python to run executable and fill in user input

╄→尐↘猪︶ㄣ 提交于 2019-11-29 02:33:24
I'm trying to use Python to automate a process that involves calling a Fortran executable and submitting some user inputs. I've spent a few hours reading through similar questions and trying different things, but haven't had any luck. Here is a minimal example to show what I tried last #!/usr/bin/python import subprocess # Calling executable ps = subprocess.Popen('fortranExecutable',shell=True,stdin=subprocess.PIPE) ps.communicate('argument 1') ps.communicate('argument 2') However, when I try to run this, I get the following error: File "gridGen.py", line 216, in <module> ps.communicate

Is there a way to read standard input with JavaScript?

社会主义新天地 提交于 2019-11-28 21:18:34
I saw this for lots of other languages but not JavaScript. I'm trying to do problems like: this (codechef.com) and of course the programs need to be able to read standard in like C++ and other languages do. EDIT: Thanks for the answers. The primary reason I want this functionality is so I can answer the questions on CodeChef; Codechef sends multiple inputs to the files/programs that are the answers (and of course the programs have to respond in the required way for the answer to be correct). Cameron It depends on the environment that your JavaScript is executing in. In the browser, there is no

Reading line by line from STDIN

烈酒焚心 提交于 2019-11-28 21:02:20
I want to do something like this: $ [mysql query that produces many lines] | php parse_STDIN.php In parse_STDIN.php file I want to be able to parse my data line by line from stdin. use STDIN constant as file handler. while($f = fgets(STDIN)){ echo "line: $f"; } Note: fgets on STDIN reads the \n character. You could also use a generator - if you don't know how large the STDIN is going to be. Requires PHP 5 >= 5.5.0, PHP 7 Something along the lines of: function stdin_stream() { while ($line = fgets(STDIN)) { yield $line; } } foreach (stdin_stream() as $line) { // do something with the contents

Pipe input to Python program and later get input from user

我只是一个虾纸丫 提交于 2019-11-28 20:35:47
问题 Let's say I want to pipe input to a Python program, and then later get input from the user, on the command line. echo http://example.com/image.jpg | python solve_captcha.py and the contents of solve_captcha.py are: import sys image_url = sys.stdin.readline() # Download and open the captcha... captcha = raw_input("Solve this captcha:") # do some processing... The above will trigger a EOFError: EOF when reading a line error. I also tried adding a sys.stdin.close() line, which prompted a

Python equivalent of Perl's while (<>) {…}?

心不动则不痛 提交于 2019-11-28 20:13:38
问题 I write a lot of little scripts that process files on a line-by-line basis. In Perl, I use while (<>) { do stuff; } This is handy because it doesn't care where the input comes from (a file or stdin). In Python I use this if len(sys.argv) == 2: # there's a command line argument sys.stdin = file(sys.argv[1]) for line in sys.stdin.readlines(): do stuff which doesn't seem very elegant. Is there a Python idiom that easily handles file/stdin input? 回答1: The fileinput module in the standard library

Non-blocking on STDIN in PHP CLI

£可爱£侵袭症+ 提交于 2019-11-28 19:40:16
Is there anyway to read from STDIN with PHP that is non blocking: I tried this: stream_set_blocking(STDIN, false); echo fread(STDIN, 1); and this: $stdin = fopen('php://stdin', 'r'); stream_set_blocking($stdin, false); echo 'Press enter to force run command...' . PHP_EOL; echo fread($stdin, 1); but it still blocks until fread gets some data. I noticed a few open bug reports about this (7 years old), so if it can't be done, does any one know any crude hacks that could accomplish this (on Windows and Linux)? https://bugs.php.net/bug.php?id=34972 https://bugs.php.net/bug.php?id=47893 https://bugs

How do you specify filenames within a zip when creating it on the command line from a pipe?

久未见 提交于 2019-11-28 19:17:36
I'm trying to create a zip file from file contents which are being piped in, e.g. mysql [params and query] | zip -q output.zip - This writes the zip correctly, but when you open the zip, the file within it is called "-". Is there any way of specifying what the filename of the piped in data should be within the zip? From what i can gather you cannot do both with the zip command, i mean you cannot both specify the filenames and pipe the content. You can either pipe the contents and the resulting file is - or you can pipe the filenames with -@ . That does not mean that doing so is impossible