pipe

Python child process loop over stdin from Node.js parent process

∥☆過路亽.° 提交于 2019-12-22 14:18:23
问题 My Node.js parent program executes a child Python process and send to it text data - see here for the implementation. This works ok, the node parent process writes data as: child.stdin.setEncoding('utf-8'); child.stdin.write(data + '\r\n'); child.stdin.end(); the Python child process echoes it back: for line in sys.stdin: ofp.write(line) and it gets back the data to the parent: child.stdout.on('data', function (_data) { var data = Buffer.from(_data, 'utf-8').toString().trim(); res += data; })

Pipe $_POST to an external command

亡梦爱人 提交于 2019-12-22 13:31:34
问题 I have a program that reads a JSON request from stdin , which I want to call in PHP. Here's what I have right now <?php echo exec( 'echo \''.json_encode($_POST,JSON_NUMERIC_CHECK).'\' | '. 'program' ); ?> This works, but is there a more direct way to put a string in PHP in stdin ? Something along the lines of pipe(json_encode($_POST,JSON_NUMERIC_CHECK),'program') maybe? What I have may be fine in this particular case, but what if instead of JSON, I'll need to pipe binary data? What if it's

Pipe $_POST to an external command

烈酒焚心 提交于 2019-12-22 13:31:06
问题 I have a program that reads a JSON request from stdin , which I want to call in PHP. Here's what I have right now <?php echo exec( 'echo \''.json_encode($_POST,JSON_NUMERIC_CHECK).'\' | '. 'program' ); ?> This works, but is there a more direct way to put a string in PHP in stdin ? Something along the lines of pipe(json_encode($_POST,JSON_NUMERIC_CHECK),'program') maybe? What I have may be fine in this particular case, but what if instead of JSON, I'll need to pipe binary data? What if it's

read() hangs on zombie process

依然范特西╮ 提交于 2019-12-22 13:01:05
问题 I have a while loop that reads data from a child process using blocking I/O by redirecting stdout of the child process to the parent process. Normally, as soon as the child process exits, a blocking read() in this case will return since the pipe that is read from is closed by the child process. Now I have a case where the read() call does not exit for a child process that finishes. The child process ends up in a zombie state, since the operating system is waiting for my code to reap it, but

What are the ways that signals can interfere with pipe communication?

为君一笑 提交于 2019-12-22 12:52:17
问题 I don't know anything about signals, and only a little about pipes. From the comments on zdim's answer here it seems that signals may interfere with pipe communication between parent and child processes. I was told that, if you're using IO::Select and sysread, then the exit of a child process could somehow mess up the behavior of IO::Select::can_read , especially if there are multiple child processes. Please describe how to account for signals when using pipes? The below code is an example

Connect pipes of processes in php

隐身守侯 提交于 2019-12-22 12:19:57
问题 I would like the output of one process created with proc_open to be piped to another one created with proc_open (in php). For example. In bash I can do: [herbert@thdev1 ~]$ cat foo 2 3 1 [herbert@thdev1 ~]$ cat foo | sort 1 2 3 [herbert@thdev1 ~]$ I would like to simulate this in php using proc_open (instead of shell_exec) in order to have control over return-codes, pipes, etc. So I want something like this: $catPipes=array(); $sortPipes=array(); $cwd = '/tmp'; $env = array(); $catProcess =

How to run a command using pipe?

故事扮演 提交于 2019-12-22 11:14:14
问题 I am trying to run ls|wc using execvp. So I create a pipe and then fork to create a child. I close the appropriate(read./write) end in parent/child and then map the other end to stdout/stdin. Then I run the ls in parent using execvp and wc in child. When I run the program it says wc:standard input:bad file descriptor. 0 0 0 wc: -:Bad file descriptor Here is my code: int main() { //int nbBytes = 0; //stream length int pfd_1[2]; //file descriptor //char buffer[MAX_FILE_LENGTH]; char* arg[MAX

How can I pipe from terminal in Perl without losing color?

百般思念 提交于 2019-12-22 10:53:56
问题 I'm trying to write a perl script which takes the output of colorgcc (or any other script that prints colored text to terminal), adds/removes parts of the string, and then prints the result in the same color as the input string. The following code will print "Hello World" in front of each line produced by the color_producing_script . The output will be all black, while the input is multicolored. How can I modified this script to conserve the original colors? open(CMD, "color_producing_script

Detecting symbolic links and pipes in Mono

允我心安 提交于 2019-12-22 10:34:43
问题 Is there a way to distinguish special files like symbolic links and pipes using C# and Mono? The application is a multi-platform backup tool, so I want to avoid using interop libraries or 'C' dll's and look for a straight managed code solution. 回答1: After digging around some more, I've found a solution. Adding a reference to Mono.Posix to a project gives access to some of the Unix file system attributes. Mono.Unix.UnixSymbolicLinkInfo i = new Mono.Unix.UnixSymbolicLinkInfo( path ); switch( i

Keeping a pipe to a process open

走远了吗. 提交于 2019-12-22 08:49:35
问题 I have an app that reads in stuff from stdin and returns, after a newline, results to stdout A simple (stupid) example: $ app Expand[(x+1)^2]<CR> x^2 + 2*x + 1 100 - 4<CR> 96 Opening and closing the app requires a lot of initialization and clean-up (its an interface to a Computer Algebra System), so I want to keep this to a minimum. I want to open a pipe in Python to this process, write strings to its stdin and read out the results from stdout . Popen.communicate() doesn't work for this, as