Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../usr/man/man3gen/p2open.3gen
Real path: /usr/share/man/man3gen/p2open.3gen
Zurück
'\" te .\" Copyright (c) 1996, 2021, Oracle and/or its affiliates. .\" Copyright (c) 1989, AT&T. All rights reserved. .TH p2open 3GEN "1 Jul 2020" "Oracle Solaris 11.4" "String Pattern-Matching Library Functions" .SH NAME p2open, p2close \- open, close pipes to and from a command .SH SYNOPSIS .LP .nf cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lgen\fR [ \fIlibrary\fR ... ] #include <libgen.h> \fBint\fR \fBp2open\fR(\fBconst char *\fR\fIcmd\fR, \fBFILE *\fR\fIfp\fR[2]); .fi .LP .nf \fBint\fR \fBp2close\fR(\fBFILE *\fR\fIfp\fR[2]); .fi .SH DESCRIPTION .sp .LP The \fBp2open()\fR function creates two pipes between the calling program and the command to be executed. The \fIcmd\fR argument consists of a shell command line. On return, \fBfp[0]\fR points to a \fBFILE\fR pointer to write the command's standard input and \fBfp[1]\fR points to a \fBFILE\fR pointer to read from the command's standard output. In this way the program has control over the input and output of the command. .sp .LP The function returns \fB0\fR if successful; otherwise, it returns \fB\(mi1\fR. .sp .LP The \fBp2close()\fR function is used to close the file pointers that \fBp2open()\fR opened. It waits for the process to terminate and returns the process status. It returns \fB0\fR if successful; otherwise, it returns \fB\(mi1\fR. .SH RETURN VALUES .sp .LP A common problem is having too few file descriptors. The \fBp2close()\fR function returns \fB\(mi1\fR if the two file pointers are not from the same \fBp2open()\fR. .SH EXAMPLES .LP \fBExample 1\fR Example of file descriptors. .sp .in +2 .nf #include <stdio.h> #include <libgen.h> main(argc,argv) int argc; char **argv; { FILE *fp[2]; pid_t pid; char buf[16]; pid=p2open("/usr/bin/cat", fp); if ( pid == \(mi1 ) { fprintf(stderr, "p2open failed\en"); exit(1); } write(fileno(fp[0]),"This is a test\en", 16); if(read(fileno(fp[1]), buf, 16) <=0) fprintf(stderr, "p2open failed\en"); else write(1, buf, 16); (void)p2close(fp); } .fi .in -2 .sp .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ MT-Level Unsafe .TE .sp .SH SEE ALSO .sp .LP \fBfclose\fR(3C), \fBpopen\fR(3C), \fBsetbuf\fR(3C), \fBattributes\fR(7) .SH NOTES .sp .LP Buffered writes on \fBfp[0]\fR can make it appear that the command is not listening. Judiciously placed \fBfflush()\fR calls or unbuffering \fBfp[0]\fR can be a big help; see \fBfclose\fR(3C). .sp .LP Many commands use buffered output when connected to a pipe. That, too, can make it appear as if things are not working. .sp .LP Usage is not the same as for \fBpopen()\fR, although it is closely related.