\ .\" This man page was generated by the Netpbm tool 'makeman' from HTML source. .\" Do not hand-hack it! If you have bug fixes or improvements, please find .\" the corresponding HTML page on the Netpbm website, generate a patch .\" against that, and send it to the Netpbm maintainer. .TH "Netpbm subroutine library: pm_system() subroutine, etc." 3 "12 May 2016" "netpbm documentation" .SH Name pm_system - run a Netpbm program with program input and output .SH Synopsis .nf \f(CW #include pm_system(void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), void * const accepterParm, const char * const shellCommand); pm_system_lp(const char * const progName, void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), void * const accepterParm, ...); pm_system_vp(const char * const progName, const char ** const argArray, void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), void * const accepterParm); pm_system2(void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), void * const accepterParm, const char * const shellCommand, int * const termStatusP ); pm_system2_lp(const char * const progName, void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), int * const terminationStatusP, void * const accepterParm, ...); pm_system2_vp(const char * const progName, const char ** const argArray, void stdinFeeder(int, void *), void * const feederParm, void stdoutAccepter(int, void *), void * const accepterParm, int * const termStatusP); \fP .fi .SH Example .PP This simple example converts a PNM image on Standard Input to a JFIF (JPEG) image on Standard Output. In this case, \fBpm_system()\fP is doing no more than \fBsystem()\fP would do. .nf \f(CW pm_system(NULL, NULL, NULL, NULL, "pnmtojpeg"); \fP .fi .PP This example does the same thing, but moves the data through memory buffers to illustrate use with memory buffers, and we throw in a stage to shrink the image too: .nf #include char pnmData[100*1024]; /* Input file better be < 100K */ char jfifData[100*1024]; struct bufferDesc pnmBuffer; struct bufferDesc jfifBuffer; unsigned int jfifSize; pnmBuffer.size = fread(pnmData, 1, sizeof(pnmData), stdin); pnmBuffer.buffer = pnmData; pnmBuffer.bytesTransferredP = NULL; jfifBuffer.size = sizeof(jfifData); jfifBuffer.buffer = jfifData; jfifBuffer.bytesTransferredP = &jfifSize; pm_system(&pm_feed_from_memory, &pnmBuffer, &pm_accept_to_memory, &jfifBuffer, "pamscale .5 | pnmtojpeg"); fwrite(jfifData, 1, jfifSize, stdout); .fi .PP This example reads an image into libnetpbm PAM structures, then brightens it, then writes it out, to illustrate use of \fBpm_system\fP with PAM structures. .nf #include #include struct pam inpam; struct pam outpam; tuple ** inTuples; tuple ** outTuples; struct pamtuples inPamtuples; struct pamtuples outPamtuples; inTuples = pnm_readpam(stdin, &inpam, sizeof(inpam)); outpam = inpam; inPamtuples.pamP = &inpam; inPamtuples.tuplesP = &inTuples; outPamtuples.pamP = &outpam; outPamtuples.tuplesP = &outTuples; pm_system(&pm_feed_from_pamtuples, &inPamtuples, &pm_accept_to_pamtuples, &outPamtuples, "ppmbrighten -v 100"); outpam.file = stdout; pnm_writepam(&outpam, outTuples); .fi .SH DESCRIPTION .PP These library functions are part of .BR "Netpbm" (1)\c \&. .PP \fBpm_system()\fP is a lot like the standard C library \fBsystem()\fP subroutine. It runs a shell and has that shell execute a shell command that you specify. But \fBpm_system()\fP gives you more control over the Standard Input and Standard Output of that shell command than \fBsystem()\fP. \fBsystem()\fP passes to the shell command as Standard Input and Output whatever is the Standard Input and Output of the process that calls \fBsystem()\fP. But with \fBpm_system()\fP, you specify as arguments subroutines to execute to generate the shell command's Standard Input stream and to process the shell command's Standard Output stream. .PP Your Standard Input feeder subroutine can generate the stream in limitless ways. \fBpm_system()\fP gives it a file descriptor of a pipe to which to write the stream it generates. \fBpm_system()\fP hooks up the other end of that pipe to the shell command's Standard Input. .PP Likewise, your Standard Output accepter subroutine can do anything it wants with the stream it gets. \fBpm_system()\fP gives it a file descriptor of a pipe from which to read the stream. \fBpm_system()\fP hooks up the other end of that pipe to the shell command's Standard Output. .PP The argument \fIstdinFeeder\fP is a function pointer that identifies your Standard Input feeder subroutine. \fBpm_system()\fP runs it in a child process and waits for that process to terminate (and accepts its completion status) before returning. \fIfeederParm\fP is the argument that \fBpm_system()\fP passes to the subroutine; it is opaque to \fBpm_system()\fP. .PP If you pass \fIstdinFeeder\fP = NULL, \fBpm_system()\fP simply passes your current Standard Input stream to the shell command (as \fBsystem()\fP would do), and does not create a child process. .PP The argument \fIstdoutAccepter\fP is a function pointer that identifies your Standard Output accepter subroutine. \fBpm_system()\fP calls it in the current process. \fIaccepterParm\fP is an argument analogous to \fIfeederParm\fP. .PP If you pass \fIstdoutAccepter\fP = NULL, \fBpm_system()\fP simply passes your current Standard Output stream to the shell command (as \fBsystem()\fP would do. .PP The argument \fIshellCommand\fP is a null-terminated string containing the shell command that the shell is to execute. It can be any command that means something to the shell and can take a pipe for Standard Input and Output. Example: .nf \f(CW ppmbrighten -v 100 | pamdepth 255 | pamscale .5 \fP .fi .PP \fBpm_system()\fP creates a child process to run the shell and waits for that process to terminate (and accepts its completion status) before returning. .PP If the shell fails, i.e. does not exit voluntarily with zero exit status, \fBpm_system\fP calls \fBpm_error()\fP, which normally issues an error message to Standard Error and exits the program. Use \fBpm_system2()\fP if you don't want that. .PP Note that the 'termination status' of a Unix process is a value which is a combination of 1) whether the process exited voluntarily or was killed by the operating system; 2) in the case of termination by the OS, what class of signal did it; and 3) in the case of voluntary exit, what 'exit status' the program declared. .SS Interface Header File .PP These interfaces are declared by \fB