stdin

Sending strings between to Python Scripts using subprocess PIPEs

雨燕双飞 提交于 2019-12-04 12:57:33
I want to open a Python script using subprocess in my main python program. I want these two programs to be able to chat with one another as they are both running so I can monitor the activity in the slave script, i.e. I need them to send strings between each other. The main program will have a function similar to this that will communicate with and monitor the slave script: Script 1 import subprocess import pickle import sys import time import os def communicate(clock_speed, channel_number, frequency): p = subprocess.Popen(['C:\\Python27\\pythonw','test.py'], stdin=subprocess.PIPE, stdout

Erlang: How to pipe stdin input from a file to an erlang program and match eof?

南笙酒味 提交于 2019-12-04 11:48:23
How to pipe input from a file as stdin to an erlang program running in the shell as well as standalone? I have a file hr.erl and I compile it from the shell. There is a function in it which accepts input from stdin using io:fread() . I have written a case expression with guards where if it matches {ok, [0]} it should terminate. Instead of 0 , I actually need it to be eof . How to send eof when running in a shell? I have a file inp.txt with values 1 2 3 and 0 on each line. How can I pass it using the < pipe operator? Is there anything like erl -hr <inp.txt ? Can I pipe it to stdin within the

using select to read from socket and stdin

匆匆过客 提交于 2019-12-04 11:28:10
I'm writing a ncurses based chat program. At first, I wrote just networking stuff (without ncurses) and everything worked fine, but after adding graphics I can't get the client app to work properly. The main problem is reading from stdin and socket at the same time. In ncurses-less version I've used pthread and it worked like charm. Alas, it seems that pthread and ncurses don't go together very well, so I had to find another solution. I thought that select() would do, but it still only reads from stdin and completely ignores the socket. Here is the whole code: code The interesting part is:

How to stop reading multiple lines from stdin using Scanner?

半世苍凉 提交于 2019-12-04 11:14:21
问题 I'm working on an JAVA assignment should process multiple lines of input. The instructions read "Input is read from stdin." An example of sample input is given: one 1 two 2 three 3 I don't understand what the above sample input "read from stdin" means. Here's a test program I wrote that isolates my confusion: import java.io.*; import java.util.Scanner; class Test { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); while(stdin.hasNextLine()) { String line = stdin

Read from pipe line by line in C

妖精的绣舞 提交于 2019-12-04 10:57:17
问题 How can I separate the lines which are coming from a pipe. In the pipe there is this text: HALLO:500\n TEST:300\N ADAD ADAWFFA AFAGAGAEG I want to separate the lines from the pipe because i want to save the values in variables. Here is my c code: #include <stdio.h> #include <stdlib.h> #define BUFFERSIZE 1 int main(int argc, char **argv){ unsigned char buffer[BUFFERSIZE]; FILE *instream; int bytes_read=0; int buffer_size=0; buffer_size=sizeof(unsigned char)*BUFFERSIZE; /* open stdin for

Asynchronously redirect stdout/stdin from embedded python to c++?

自作多情 提交于 2019-12-04 10:38:15
问题 I am essentially trying to write a console interface with input and output for an embedded python script. Following the instructions here, I was able to capture stdout: Py_Initialize(); PyRun_SimpleString("\ class StdoutCatcher:\n\ def __init__(self):\n\ self.data = ''\n\ def write(self, stuff):\n\ self.data = self.data + stuff\n\ import sys\n\ sys.stdout = StdoutCatcher()"); PyRun_SimpleString("some script"); PyObject *sysmodule; PyObject *pystdout; PyObject *pystdoutdata; char *string;

How to process stdin to stdout in php?

只愿长相守 提交于 2019-12-04 10:10:33
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 pipeline. Any clues as to why this is not working? PS: I'm not very experienced with PHP. If you are piping

How to write to stdin of execved process?

前提是你 提交于 2019-12-04 09:33:17
I'm trying to execve a process that reads from stdin. I want to prepare stdin with some data so it can execute successfully. How can I do that? You will need to fork the execve call into a child process and then create a pipe from the parent process to the child's stdin. Take a look at this link for a detailed example on how to use pipes: http://tldp.org/LDP/lpg/node11.html 来源: https://stackoverflow.com/questions/12611457/how-to-write-to-stdin-of-execved-process

Can anyone give me a quick tutorial in stdin and stdout in Python 3? [closed]

为君一笑 提交于 2019-12-04 08:44:51
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I know this sounds like something I can google, but the truth is that I don't find or do not understand what the very few Python 3

Read from stdin write to stdout in C

戏子无情 提交于 2019-12-04 08:23:10
问题 I am trying to write a cat clone to exercise C, I have this code: #include <stdio.h> #define BLOCK_SIZE 512 int main(int argc, const char *argv[]) { if (argc == 1) { // copy stdin to stdout char buffer[BLOCK_SIZE]; while(!feof(stdin)) { size_t bytes = fread(buffer, BLOCK_SIZE, sizeof(char),stdin); fwrite(buffer, bytes, sizeof(char),stdout); } } else printf("Not implemented.\n"); return 0; } I tried echo "1..2..3.." | ./cat and ./cat < garbage.txt but I don't see any output on terminal. What I