1 int main(int argc, char *argv[], char *envp[])
4 /* create two pipes, pipein and pipeout, to handle communication */
5 if ( (retval = pipe(pipein)) ) {
6 WriteMess("input pipe creation error");
9 if ( (retval = pipe(pipeout)) ) {
10 WriteMess("output pipe creation error");
13 /* First fork: use child to run barcode program */
14 if ( (pid = fork()) == -1) { /* on error exit */
15 WriteMess("child creation error");
20 close(pipein[1]); /* close pipe write end */
21 dup2(pipein[0], STDIN_FILENO); /* remap stdin to pipe read end */
23 dup2(pipeout[1], STDOUT_FILENO); /* remap stdout in pipe output */
24 execlp("barcode", "barcode", size, NULL);
26 close(pipein[0]); /* close input side of input pipe */
27 write(pipein[1], argv[1], strlen(argv[1])); /* write parameter to pipe */
28 close(pipein[1]); /* closing write end */
29 waitpid(pid, NULL, 0); /* wait child completion */
30 /* Second fork: use child to run ghostscript */
31 if ( (pid = fork()) == -1) {
32 WriteMess("child creation error");
35 /* second child, convert PS to JPEG */
37 close(pipeout[1]); /* close write end */
38 dup2(pipeout[0], STDIN_FILENO); /* remap read end to stdin */
40 write(STDOUT_FILENO, content, strlen(content));
41 execlp("gs", "gs", "-q", "-sDEVICE=jpeg", "-sOutputFile=-", "-", NULL);
45 waitpid(pid, NULL, 0);