pipe

dup2() and exec()

巧了我就是萌 提交于 2019-12-23 09:51:32
问题 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> int main( int argc, char **argv) { int pfds[ 2], i; size_t pbytrd; pid_t childpid; char buffer[ 200]; pipe( pfds); if( ( childpid = fork() ) == -1) { perror( "fork error: "); exit( 1); } else if( childpid == 0) { close( pfds[ 0]); dup2( pfds[1], 1); close( pfds[ 1]); for( i = 0; i < 10; i++) printf("Hello..."); execlp( "xterm","xterm","-e","./sample_a", (char *) 0); exit( 0); } else { close( pfds

POSIX: Pipe syscall in FreeBSD vs Linux

风格不统一 提交于 2019-12-23 08:17:10
问题 In Linux (2.6.35-22-generic), man pipe states that pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication." In FreeBSD (6.3-RELEASE-p5), man pipe states that The pipe() system call creates a pipe, which is an object allowing bidirectional data flow, and allocates a pair of file descriptors." One is unidirectional, the other is bidirectional. I hope this isn't a silly question, but which method is the standard way of doing this? Are they both POSIX

POSIX: Pipe syscall in FreeBSD vs Linux

荒凉一梦 提交于 2019-12-23 08:17:10
问题 In Linux (2.6.35-22-generic), man pipe states that pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication." In FreeBSD (6.3-RELEASE-p5), man pipe states that The pipe() system call creates a pipe, which is an object allowing bidirectional data flow, and allocates a pair of file descriptors." One is unidirectional, the other is bidirectional. I hope this isn't a silly question, but which method is the standard way of doing this? Are they both POSIX

how to use stdin pipe as source input for gcc?

笑着哭i 提交于 2019-12-23 08:03:25
问题 This is my try: CMD file: @SET PATH=%PATH%;D:\mingw\bin type test10.cpp | g++ -xc++ -o test10.exe code (irrelevant here): int main() {} error I get: g++: fatal error: no input files compilation terminated. I thought that the -x option is for signalizing stdin input, gcc itself said me that. 回答1: The -x option specifies the input language, but it doesn't tell g++ to read from stdin. To do that, you can pass a single dash as a file name. type test10.cpp | g++ -o test10.exe -x c++ - 来源: https:/

Java idiom for “piping”

僤鯓⒐⒋嵵緔 提交于 2019-12-23 07:30:31
问题 Is there a more concise/standard idiom (e.g., a JDK method) for "piping" an input to an output in Java than the following? public void pipe(Reader in, Writer out) { CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE); while (in.read(buf) >= 0 ) { out.append(buf.flip()); buf.clear(); } } [EDIT] Please note the Reader and Writer are given . The correct answer will demonstrate how to take in and out and form a pipe (preferably with no more than 1 or 2 method calls). I will accept answers

extend a pipe like currency or number on a custom pipe on angular2

限于喜欢 提交于 2019-12-23 07:13:45
问题 I would like to call the numberPipe on my custom pipe I find this answer Angular2 use basic pipe in custom pipe but I this solution don't work for me. I have an error "The pipe 'bigInteger' could not be found" import { Pipe, PipeTransform } from "@angular/core" import { CurrencyPipe } from "@angular/common" @Pipe({ name: "bigInteger" }) export class BigInteger extends CurrencyPipe implements PipeTransform { transform(value: any): string { return value } } 回答1: update this should be fixed

How To Receive Output From A Child Process' STDOUT Without Blocking or Poling

白昼怎懂夜的黑 提交于 2019-12-23 05:50:39
问题 I have a long-running console-based application Sender that sends simple text to STDOUT using non-buffered output such as cout << "Message" << flush() . I want to create an MFC dialog-based application (named Receiver ) that starts Sender and can read it's output. Receiver should also be able to detect when Sender has died, or be able to kill Sender if it wants to. Sender knows nothing of Reciever , and I can't change Sender 's code. My first attempt was to create pipes with redirected STDIN

Unix Pipes - Pipeline between three processes

老子叫甜甜 提交于 2019-12-23 05:43:07
问题 I'm creating a small program which contains three processes; a source process, a filter process and a sink process. The stdout of the source process is redirected to the stdin of the filter process, and the filter process' stdout is redirected to the sink process' stdin. My problem is that no output is printed to stdout from the sink process. Can any of you see the problem in the following tiny snippet of code? #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char

Writing mulitple times in a special (given) pipe C++

╄→尐↘猪︶ㄣ 提交于 2019-12-23 05:20:23
问题 I try to handle some pipes in a CAD Programm with c++. The programm Geograf has two pipes. They are both in the following path: \.\pipe\GGPIPE The interesting on this pipe is, that I have to open a pipe then close a pipe and open a pipe again. After this steps, I can send commands through the pipe to Geograf. My problem or question is, why I can write to pipe the only one time ? After I excecute my program the second time, the handle have a INVALID_HANDLE_VALUE. If I want to send a command

Can I pipe ispell output to an array?

梦想与她 提交于 2019-12-23 05:01:46
问题 I need to somehow get the output of ispell -l into an array so that I can loop through them.. So far ive got this cat $1 | ispell -l I have tried to read them in line by line into an array but that hasnt worked for me any suggestions? 回答1: Recent bash comes with mapfile or readarray : readarray stuff < <(ispell -l < "$1") echo "number of lines: ${#stuff[@]}" ( this example returns effectively ispell -l < "$1"|wc -l ) beware of the mistake to do e.g. ls | readarray , it won't work because