pipe

How do I create a pipe between two processes in Guile?

蓝咒 提交于 2021-02-18 18:52:02
问题 I want to create two process in Guile and send the output (stdout) from one of them as input (stdin) to the other. Using the following example, how can this be done? echo "foo bar" | wc Output: 1 2 8 回答1: Yes, you can do this using open-output-pipe : (let ((p (open-output-pipe "wc"))) (display "The quick brown fox jumps over the lazy dog.\n" p) (close-pipe p)) This is equivalent to echo "The quick brown fox jumps over the the lazy dog." | wc (including echo 's implicit newline because I'm

How do I create a pipe between two processes in Guile?

倾然丶 夕夏残阳落幕 提交于 2021-02-18 18:51:09
问题 I want to create two process in Guile and send the output (stdout) from one of them as input (stdin) to the other. Using the following example, how can this be done? echo "foo bar" | wc Output: 1 2 8 回答1: Yes, you can do this using open-output-pipe : (let ((p (open-output-pipe "wc"))) (display "The quick brown fox jumps over the lazy dog.\n" p) (close-pipe p)) This is equivalent to echo "The quick brown fox jumps over the the lazy dog." | wc (including echo 's implicit newline because I'm

how to read from stdout in C

若如初见. 提交于 2021-02-18 12:45:09
问题 I need to write a C program ( myprogram ) which checks output of other programs. It should basically work like this: ./otherprogram | ./myprogram But I could not find how to read line-by-line from stdout (or the pipe), and then write all this to stdout . 回答1: Create an executable using: #include <stdio.h> int main() { char line[BUFSIZ]; while ( fgets(line, BUFSIZ, stdin) != NULL ) { // Do something with the line of text } } Then you can pipe the output of any program to it, read the contents

Pipe and Tap VS subscribe with ngxs

自闭症网瘾萝莉.ら 提交于 2021-02-18 10:16:06
问题 I am playing around with pipe and subscribe. If I am using pipe with tap, nothing will log in console. If I am using subscribe, it's working. So what I am doing wrong? import { Observable } from 'rxjs'; import { tap, take } from 'rxjs/operators'; this.store.select(state => state.auth.authUser).pipe( take(1), tap((data) => { //Not Working - no console output console.log('[Tap] User Data', data); }) ); this.store.select(state => state.auth.authUser).subscribe((data) => { // Working - user data

What happens when you call close() on a pipe file descriptor that was duplicated with dup2()?

两盒软妹~` 提交于 2021-02-17 04:52:34
问题 I have a question regarding file descriptors in Unix and C programming. Let's say I use pipe(fd) to get file descriptor 3 and 4 for the pipe ends, 3 connects to the read end and 4 to the write end. Now I use dup2(fd[write_end],1) to copy the descriptor of the write end (which was 4) to file descriptor 1 in my process. If I now do close(fd[write_end]) will it close descriptor 1 or descriptor 4? 回答1: After a successful call to dup2 , both file descriptors are valid. When you then call close(fd

Why is it that my pipe does not read in the printf despite replacing stdin?

£可爱£侵袭症+ 提交于 2021-02-11 18:23:51
问题 The objective is to use dup, dup2 and pipe to communicate between parent and child processes. Just to get a feel of how to use dup and pipes. The function multby, called in by the child process, takes a number as an argument (3) and multiply it with a user input (in this case 5 as printed in parent) to get a product. (which should be 15) #include <stdio.h> #include <unistd.h> void main(int argv, char *argc) { int testpipe[2]; pipe(testpipe); int PID = fork(); if (PID == 0) { dup2(testpipe[0],

is this even possible? send commands/objects from one python shell to another?

故事扮演 提交于 2021-02-11 06:26:10
问题 I have a question I wasn't really able to solve after doing a little digging, and this is also not my area of expertise so I really don't even know what I'm looking for. I'm wondering if it's possible to "link" together two python shells? This is the actual use case... I am working with a program that has it's own dedicated python shell built into the GUI. When you run commands in the internal python shell, the GUI updates in real-time reflecting the commands you ran. The problem is, the

How to make wc accept a pipe file to take input from instead of stdin?

≯℡__Kan透↙ 提交于 2021-02-10 18:33:15
问题 This is a homework problem. The task is to replicate the command: ls | wc -l in a C program using execlp , fork , and pipes. My Approach I think the problem can be solved this way: Create a pipe file: pipe.txt Create a child process using fork() Map the stdout of the child process to pipe.txt Execute ls using execlp This puts the output of ls into pipe.txt Inside of parent process Map the stdin of the parent process to pipe.txt Execute wc -l using execlp without giving any further arguments

Boost::Process Pipe Streams and Unit Test

偶尔善良 提交于 2021-02-10 15:56:17
问题 I have source which two stream like this: bp::ipstream StdOut; bp::opstream StdIn; bp::child MyProcess = bp::child(processPath, bp::std_out > StdOut, bp::std_in < StdIn); // Doing some stuff with StdOut and StdIn I wanted to know if there is a way to write manually into this StdOut and read from StdIn in order to do unit tests? Thank you very much! 回答1: You can write to them as a normal stream: Live On Coliru #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int

Capturing stdout/stderr separately and simultaneously from child process results in wrong total order (libc/unix)

天涯浪子 提交于 2021-02-10 14:43:49
问题 I'm writing a library that should execute a program in a child process, capture the output, and make the output available in a line by line (string vector) way. There is one vector for STDOUT, one for STDERR, and one for "STDCOMBINED", i.e. all output in the order it was printed by the program. The child process is connected via two pipes to a parent process. One pipe for STDOUT and one for STDERR. In the parent process I read from the read-ends of the pipes, in the child process I dup2() 'ed